jQuery手风琴用于多个嵌套列表 [英] jQuery accordion for multiple nested lists
问题描述
我正在努力合并菜单的第二个嵌套列表,以便他们可以打开onclick.下面是我的代码.
I'm struggling to incorporate the second nested list of my menu so that they can open onclick. Below is my code.
另外,我如何做到这一点,因此单击以展开列表不会触发任何其他事件?现在,如果您单击它们,我的整个菜单就会从另一个脚本关闭(这是针对移动响应菜单的),因此,如果我的菜单项li具有嵌套列表,我希望单击仅打开或关闭其嵌套列表并执行没什么.
Also, how can I make it so clicking to expand a list doesn't trigger any other events? Right now if you click them, my entire menu slides closed from another script (this is for a mobile responsive menu) So if my menu-item li has a nested list, I want the click to ONLY open or close its nested list and do nothing else.
http://jsfiddle.net/notanothercliche/36vCh/
<ul class="menu" id="menu-menu">
<li class="menu-item>Home</li> <!-- end Home menu-item -->
<li class="menu-item>Properties
<ul class="dropdown-menu">
<li class="menu-item>Dubai
<ul class="dropdown-menu">
<li class="menu-item>Residential
<ul class="dropdown-menu">
<li class="menu-item>Apartments</li>
<li class="menu-item>Villas</a></li>
</ul> <!-- end Residential dropdown-menu -->
</li> <!-- end Residential menu-item -->
</ul> <!-- end Dubai dropdown-menu -->
</li> <!-- end Dubai menu-item -->
</ul> <!-- end Properties dropdown-menu -->
</li> <!-- end Properties menu-item -->
</ul> <!-- end menu-menu -->
推荐答案
您不必这么费劲.可能不需要像您一样操作类.
You don't have to work so hard. There's probably no need to manipulate classes like you are.
http://jsfiddle.net/isherwood/36vCh/6
jQuery("#menu-menu a").on("click", function (e) {
if (jQuery(this).parent().has("ul")) {
e.preventDefault();
}
$(this).next('ul').slideToggle();
});
请注意,我添加了一些缺少的引号和必需的href属性.
Note that I added a few missing quotes and required href attributes.
这篇关于jQuery手风琴用于多个嵌套列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!