我已將原型庫添加到我的網站,然後添加下面的代碼。當我打開頁面時,我想隱藏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>
謝謝。
使用$$('。block-category> li> ul')。hide(); – theshadowmonkey