当我点击父级进行客户端导航时,我正在使嵌套的ul向下滑动,因此父链接将被停用并返回false。但返回false也会停用子链接,我该如何避免这种情况呢?
$("li.page_item a:first-child").click(function() {
//select it's direct sub ul
var subnav = $(this).next();
//other subnavs
var navsibling = $(this).parent().siblings('li').children('ul');
//hide siblings subnav
if (navsibling.is(":open")) {
navsibling.slideUp("slow");
}
// check to see if sub is hidden, open if it is, close if it isn't
if (subnav.is(":hidden")) {
subnav.slideDown("slow");
} else {
subnav.slideUp("slow");
}
// stop the top level link from linking
return false;
});
我认为使用a:first-child只会将返回false应用于特定的a而不是其中任何一个兄弟的孩子...建议?
编辑:它是wordpress中的列表页面小部件,基本上是标记:
<ul>
<li class="page_item"><a href="">Link</a>
<ul>
<li><a href="">SubLink</a></li>
<li><a href="">SubLink</a></li>
<li><a href="">SubLink</a></li>
<li><a href="">SubLink</a></li>
</ul>
</li>
<li class="page_item"><a href="">Link</a>
<ul>
<li><a href="">SubLink</a></li>
<li><a href="">SubLink</a></li>
<li><a href="">SubLink</a></li>
<li><a href="">SubLink</a></li>
</ul>
</li>
</ul>
答案 0 :(得分:2)
试
$("li.page_item").children("a:first-child").click(function() {