JavaScript:
function showOrHide()
{
var div = document.getElementByClass("showorhide");
if (div.myDivClass.display == "block")
{
div.myDivClass.display = "none";
}
else
{
div.myDivClass.display = "block";
}
}
CSS:
.showorhide {
display: none;
padding: 12px 0px 12px 0px;
}
html:
<div align="left" style="padding-bottom:3px;"><font size="5">Chat Issues:</font></div>
<a href="javascript:showOrHide();"><font size="3">Are there any age requirements?</font></a>
<ul style="margin:0px 0px 0px 0px;">
<div class="showorhide">
<li>Yes. You must be 13 years of age or older to use our chatrooms. Anyone under the age of 13 will be directed to a chatroom more suitable for their age.</li>
</div>
</ul>
<a href="javascript:showOrHide();"><font size="3">Can i advertise in your chatroom? </font></a>
<ul style="margin:0px 0px 0px 0px;">
<div class="showorhide">
<li>Absolutely not! Advertising is strictly prohibited and anyone caught advertising will be banned without warning.</li>
</div>
</ul>
它曾经有一个 div id 效果很好,但我需要使用相同的 id 和多个显示/隐藏而不更改 id 并制作大量代码,所以我尝试将它更改为一个类,但我似乎无法得到它去工作。它隐藏了内容,但点击时不会显示出来,有什么建议吗?