所以我在 JQuery 中痛苦地得到了多个下拉菜单切换状态(隐藏和显示),但我有一些代码告诉侧边栏哪个页面处于事件状态并为其提供事件样式,我想要一个下拉菜单如果有 child 在其中事件,则不会隐藏。
如果您点击查看下拉菜单的顶级链接有一个活跃的子级,那么它会被赋予 id“HAC”(有活跃的子级),但我想我可能会为此烧脑。
Here's a jsfiddle page with the working demo of the problem.
下拉列表在导航中的设置如下
<ul id="HAC" class='topLevel'>
<li class='subItem'>
<a class="active" href='thatpage.php'>That page</a>
</li>
<li class='subItem'>
<a href='thatotherpage.php'>That other page</a>
</li>
</ul>
提前感谢您的帮助
最佳答案
我认为您正在寻找的是 jQuery :not selector 。这是an update to your fiddle
function dropDowns() {
//for each toplevel li a
$(".topLevel:not(#HAC) li a").each(function() {
//hide subitems if not HAC (has active children)
$(this).hide();
});
//Toggle show them on click
clickToggle();
}
关于javascript - 根据一个子jquery单独隐藏下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18777165/