已更新以包含更多代码
我们的网页设计师中风了,我一直在努力在他缺席的情况下完成一些设计。看来他不太可能帮助我。
我一直在使用打字板,其中一个页面有常见问题解答并使用 JavaScript,因此如果您单击问题,答案就会显示。然后,如果您单击答案文本,它会再次消失。我更新了一些答案文本,它似乎以某种方式破坏了 javascript 链接。我一直在做教程并尝试学习如何修复它。现在它只显示问题和答案,点击显示功能已丢失。
我们的设计师使用了 onclick=toggle
我已在此处包含代码(为了简洁,将答案文本替换为答案 1),看看是否有人可以指出它是如何损坏的/我如何修复它。可悲的是我对此的经验为零。非常感谢你:)
<p>FAQ Display</p>
<script type="text/javascript">// <![CDATA[
function toggle(Info) {
var CState = document.getElementById(Info);
CState.style.display = (CState.style.display != 'block')
? 'block' : 'none';}
// ]]></script>
<div><strong>Click on the question to reveal the answer!</strong><br /><br /></div>
<h3>Services</h3>
<div class="FAQ" onclick="toggle('faq17')"><strong>Why use this service? </strong>
<div id="faq17" class="FAA">Answer 17.</div>
</div>
<div class="FAQ" onclick="toggle('faq1')"><strong>How much does the cleaning and labelling service cost?</strong>
<div id="faq1" class="FAA">Answer 1.</div>
</div>
<div class="FAQ" onclick="toggle('faq2')"><strong>How do I book the service? </strong>
<div id="faq2" class="FAA">Answer 2.</div>
</div>
<div class="FAQ" onclick="toggle('faq3')"><strong>How long does the service take?</strong>
<div id="faq3" class="FAA">Answer 3.</div>
</div>
<div class="FAQ" onclick="toggle('faq4')"><strong>Is there a minimum number of residents required to visit my facility?</strong>
<div id="faq4" class="FAA">Answer 4.</div>
</div>
<h3>DIY Kits</h3>
<div class="FAQ" onclick="toggle('faq5')"><strong>Where can I purchase a kit from?</strong>
<div id="faq5" class="FAA">Answer 5.</div>
</div>
<div class="FAQ" onclick="toggle('faq6')"><strong>How much does a DIY kit cost?</strong>
<div id="faq6" class="FAA">Answer 6.</div>
</div>
<div class="FAQ" onclick="toggle('faq7')"><strong>How long will my kit last? </strong>
<div id="faq7" class="FAA">Answer 7.</div>
</div>
<div class="FAQ" onclick="toggle('faq8')"><strong>Do the kits expire?</strong>
<div id="faq8" class="FAA">Answer 8.</div>
</div>
<div class="FAQ" onclick="toggle('faq9')"><strong>Is there a material data safety sheet (SDS) for the kits?</strong>
<div id="faq9" class="FAA">Answer 9. <span class="asset asset-generic at-xid-6a01b7c6f66688970b01bb088843a0970d img-responsive"><a href="http://www.identoz.com.au/files/sds-identoz-denture-marking-sealant-version-1.0.pdf">Download SDS iDentOz Denture Marking Sealant Version 1.0</a> </span></div>
</div>
<h3>Generic Questions</h3>
<div class="FAQ" onclick="toggle('faq10')"><strong>Where is the label placed on the denture?</strong>
<div id="faq10" class="FAA">Answer 10.</div>
</div>
<div class="FAQ" onclick="toggle('faq11')"><strong>Do you service all areas? </strong>
<div id="faq11" class="FAA">Answer 11.</div>
</div>
<div class="FAQ" onclick="toggle('faq12')"><strong>How do I make payment? </strong>
<div id="faq12" class="FAA">Answer 12.</div>
</div>
<div class="FAQ" onclick="toggle('faq13')"><strong>Are our staff police checked?</strong>
<div id="faq13" class="FAA">Answer 13.</div>
</div>
<div class="FAQ" onclick="toggle('faq14')"><strong>Is your work guaranteed?</strong>
<div id="faq14" class="FAA">Answer 14.</div>
</div>
<div class="FAQ" onclick="toggle('faq15')"><strong>Do you repair dentures? </strong>
<div id="faq15" class="FAA">Answer 15.</div>
</div>
<div class="FAQ" onclick="toggle('faq16')"><strong>Do you have insurance? </strong>
<div id="faq16" class="FAA">Answer 16.</div>
</div>
<p><hr class="at-page-break" /></p>
不是支持你想要的,但这可能对你有用:
<html><head>
<script type="Text/JavaScript"> function displayanswer(){
document.getElementById('question').innerHTML = ' //Put answer here'}
</script>
</head><body>
<h1>Press on the question for answer</h1>
<button onclick="displayanswer"><h2 id="question"> //put your question here </h2></button>
</body></html>
我不确定代码的另一部分是否会导致此问题。
我在这里将其分解为jsfiddle:Fiddle
.FAA {
display:none;
}
我刚刚添加了样式以最初将其隐藏。您可以切换它,如果您可能遇到其他问题,请告诉我
要将其包含在您的页面上,您只需在标签之前添加此行即可
<head>
<!--May have other code here -->
<style>
.FAA { display:none; }
</style>
</head>
这可能是最简单的方法
您不需要 JavaScript 来执行此操作。您可以使用
details
使用纯 HTML 创建点击显示答案元素。
details {
margin: 0.3em 0;
}
summary {
list-style: none;
font-weight: bold;
}
<h1>FAQ Display</h1>
<p><strong>Click on the question to reveal the answer!</strong></p>
<h2>Services</h2>
<details>
<summary>Why use this service?</summary>
Answer 17.
</details>
<details>
<summary>How much does the cleaning and labelling service cost?</summary>
Answer 1.
</details>
<details>
<summary>How do I book the service?</summary>
Answer 2.
</details>
<p><hr class="at-page-break" /></p>
来源:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details