jQuery:link不起作用.toggle() [英] jQuery: link doesn't work after .toggle()
问题描述
我刚刚建立了一个下拉菜单,我想点击一下,然后点击另一个后点击。这完全适用于我已经使用的切换,但问题是在下拉菜单后,链接不执行。
I've just build a dropdown menu which I would like to drop down on a click, and go back up after an other click. This perfectly works with a toggle I have used, but the problem is that after the dropdown, the links don't execute.
$(function(){
$(function() {
$("#nav_menu-2 ul.menu ul").css({ display: 'none' });
$("#nav_menu-2 ul.menu #testbutton").toggle(function() {
$(this).find('ul.sub-menu')
.stop(true, true).delay(50).animate({ "height": "show", "opacity": "show" }, 300 );
}, function(){
$(this).find('ul.sub-menu')
.stop(true, true).delay(50).animate({ "height": "hide", "opacity": "hide" }, 300 );
});
});
所以我的大脑是,在菜单删除后,它会一点点备份,而不是执行链接。但是,由于我对javascript / jQuery很新,我不知道还有其他选项。任何想法?
So my geuss is that after the menu has dropped, it goes back up on a click, instead of executing the link. But since I'm quite new to javascript/jQuery, I have no idea what other option I have. Any ideas?
推荐答案
我会改用 slideToggle ,绑定到应该打开菜单的按钮的点击事件:
I would instead use slideToggle, bound to the click event of the button that should open the menu:
$("#nav_menu-2 ul.menu #testbutton").click(function() {
$('ul.sub-menu').slideToggle();
});
您可能需要稍微更改选择器,具体取决于您的菜单构建方式。
You might have to change the selectors slightly depending how your menu is constructed.
这篇关于jQuery:link不起作用.toggle()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!