点击此处,找到答案

时间:2015-10-31 02:47:52

标签: javascript jquery html onclick toggleclass

更新以包含更多代码

我们的网站设计师已经中风,我一直试图在他缺席时完成一些设计。他似乎不太可能帮助我。

我一直在使用typepad,其中一个页面有常见问题解答并使用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.&nbsp; <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>

2 个答案:

答案 0 :(得分:1)

我不确定你代码的另一部分是否会导致这种情况中断。

我把它分成了一个jsfiddle:Fiddle

.FAA {
    display:none;
}

我刚刚添加了样式,最初将其隐藏起来。您可以使用它进行切换,如果您可能遇到其他问题,请告知我们

要在您的网页上添加此内容,您只需在标记

之前添加此行即可
<head>
<!--May have other code here -->
<style>
.FAA { display:none; }
</style>
</head>

这可能是最简单的方法

答案 1 :(得分:1)

不要支持你想要的东西,但这可能对你有用:

<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>