单击另一个菜单项时的“隐藏/切换"子菜单 [英] Hide/Toggle submenu when clicking on another menu item
本文介绍了单击另一个菜单项时的“隐藏/切换"子菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我现在拥有的: JSfiddle
This is what I have right now: JSfiddle
当您单击类别1,然后单击类别2时,我希望关闭类别1的子菜单.我该如何实现?
When you click on Category 1 and then on Category 2, I would like the sub menu of Category 1 to close. How can I achieve that?
我现在所要做的就是单击屏幕上除菜单以外的任何地方时关闭子菜单:
All I have achieved right now, is to close the sub menu(s) when clicking anywhere on the screen except on the menu:
$(function () {
$('nav ul li').not("nav ul li ul li").click(function(e){
$(this).children('ul').stop().toggle();
e.stopPropagation();
});
$("nav ul li ul li").click(function(e){
$(this).children('ul').stop().toggle();
e.stopPropagation();
});
});
$(document).click(function() {
$("nav ul li ul").hide();
});
非常感谢您的任何答复!
Thanks a lot for any responses!
推荐答案
只需在切换当前li之前隐藏所有li--p
Just hide all li's before toggling current li -
$('nav ul li').not("nav ul li ul li").click(function (e) {
e.stopPropagation();
$("nav ul li ul").hide();
$(this).children('ul').stop().toggle();
});
演示----->
http://jsfiddle.net/rd6bX/17/
这篇关于单击另一个菜单项时的“隐藏/切换"子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文