不正确的切换 (jQuery)
我的页面上有一个简单的菜单,它使用此 jquery 代码进行基本切换:
$("#left-nav .block h3").click(function(){
$(this).next("ul").slideToggle("fast");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});
默认情况下,UL 是打开的(通过 CSS 显示:阻止),因此第一次单击时,UL 会隐藏(这很好),但它也将“活动”类添加到刚刚关闭的菜单中!我理解它在技术上是正确的,但它不是预期的结果。
我应该在代码中更改什么,以便在菜单已打开时执行 X,在相反时执行 Y。
谢谢!
I've a simple menu on my page, that uses this jquery code for basic toggling:
$("#left-nav .block h3").click(function(){
$(this).next("ul").slideToggle("fast");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});
The UL is open (display:block via CSS) by default, so on first click, the UL hides (which is fine), but it also adds the "active" class to a menu which just closed! I understand its technically correct, but it not the desired result.
What do I change in the code so it does X when menu is already open and Y when opposite.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您正在寻找 .toggle?
因此,最初单击时它会执行 X,或者执行 Y。
Maybe you're looking for .toggle?
So initially on click it does X, alternatively it does Y.