我已将原型库添加到我的站点,然后添加以下代码。当我打开页面时,我希望隐藏 ul 中的所有内容。
Event.observe(window, 'load', function() {
$$('.block-category li.parent ul').hide() //why this line doesn't work
$$('.block-category li.parent > a span').each(function (element) {
element.observe('click', function (e) {
e.element().up().next('ul').toggle();
e.preventDefault();
});
});
});
html:
<div class="block block-category">
<li class="level-top parent">
<a href="example.com/...."><span>text one</span></a>
<ul> //the 1 ul
<li><a><span>....</span></a></li>
<li><a><span>....</span></a></li>
<li><a><span>....</span></a></li>
<li><a><span>....</span></a></li>
</ul>
</li>
<li class="level-top"><a href="..."><span>....</span></a></li>
<li class="level-top parent">
<a href="example.com/...."><span>text two</span></a>
<ul> //the 2 ul
<li><a><span>....</span></a></li>
</ul>
</li>
<li class="level-top parent">
<a href="example.com/...."><span>text three</span></a>
<ul>
<li><a><span>....</span></a></li>
<li><a><span>....</span></a></li>
</ul>
</li>
</div>
谢谢你。