问题描述
|
$(\"#nav ul li:not(:has(li.current))\")
.find(\"ul\").hide().end() // Hide all other ULs
.click(function() {
$(this).children(\'ul\').slideToggle(\'fast\');
});
我上面的代码使用了一个嵌套的ul li,并在单击时扩展了级别。但是,我想在第二次单击时收缩该级别,但是上述收缩了所有级别,而不仅仅是收缩了一个级别。
编辑:例如看这个
解决方法
我不确定您打算做什么,但我认为您可以100%地确定事件是否源自处理程序元素,从而避免了不必要的滑动:
$(document).ready(function() {
$(\"#nav ul li:not(:has(li.current))\").find(\"ul\").hide().end() // Hide all other ULs
.click(function(e) {
if (this == e.target) { // if the handler element is where the event originated
$(this).children(\'ul\').slideToggle(\'fast\');
}
});
});
jsFiddle
,您可以只使用toggle()并返回false来停止传播:
Use This Example