嗨,我正在构建这个滚动框,它有一个内置的隐藏下拉列表。好吧,实际上不是一个下拉列表,而是一个下拉列表。我的问题是我不知道如何将 javascript 的脚本从 ID 更改为 CLASS。这样我就可以在滚动框中列出的所有项目上使用该 javascript。现在我只是将 javascript 的脚本嵌入到 html 文档中,而不是作为链接。
这是到目前为止的样子:
标头中的 Javascript
<script>
function unhide(divID) {
var item = document.getElementById(divID);
if (item) { item.className=(item.className=='hidden')?'unhidden':'hidden'; }
}
< /script >
有问题的代码
<ol align="center" style="font-weight: bold">Item</ol><!--Box Title-->
<div id="f1" style="height: 80px; width: 150px; overflow: scroll; border: 9px groove #FFC400"><!--scroll box-->
<!--subject 1-->
<div>
<a href="javascript:unhide('learnHTML');">Name1 </a>
</div>
<div id="LearnHTML" class="hidden">
<ul>
<li><a href=""> info/description </a></li>
<li><a target="_blank" href="">CLICK HERE TO PLAY</a></li>
</ul>
</div>
<!--subject 2-->
<a href="javascript:unhide('learnHTML');">Name2 </a>
<div>
<div id="LearnHTML" class="hidden">
<ul>
<li><a href=""> info/description </a></li>
<li><a target="_blank" href="">CLICK HERE TO PLAY</a></li>
</ul>
</div>
<!--subject 3-->
<a href="javascript:unhide('learnHTML');">Name3 </a>
<div>
<div id="LearnHTML" class="hidden">
<ul>
<li><a href=""> info/description </a></li>
<li><a target="_blank" href="">CLICK HERE TO PLAY</a></li>
</ul>
</div>
</div> <!--End Scroll Box-->
</div>
因此,所有列出的项目的下拉列表,滚动框中列出的项目,在单击列出的项目之前都是隐藏的。此外,通过再次单击同一列出的项目,它将再次隐藏其下拉菜单。
Basically, I want all the listed items in the scroll box to act the same as the first listed item does. But, I cannot figure out how to change the Javascript's Id to a class to make this work.
I tried changing the Javascript's Id to a class on my own, by doing this:
< script >
function unhide(divClass) { var item = document.getElementByClassName(divClass); if (item) { item.className=(item.className=='hidden')?'unhidden':'hidden'; } } < /script >
Then I changed the id="LearnHTML"
to class="LearnHTML"
, but it didn't worked. So, does anyone knows how to go about in making it work?
CSS for the listed items:
.hidden { display: none;}
.unhidden {
display: block;
background-color:orange;
font: white;
align:left
}