[英]Prevent Bootstrap dropdown menu toggle on click
This was asked quite a few times before, but I can't find a proper solution yet. 之前已经问过好几次了,但是我找不到合适的解决方案。 I am toggling navbar dropdown menus on hover with the following code:
我使用以下代码在悬停时切换导航栏下拉菜单:
$(".nav .dropdown").hover(function() {
$(this).find(".dropdown-toggle").dropdown("toggle");
});
which works just fine. 效果很好。 However, clicking on the
.dropdown-toggle
button toggles the menu as well, which I want to avoid. 但是,单击
.dropdown-toggle
按钮也可以切换菜单,我想避免这种情况。 Any suggestions on the code? 关于代码有什么建议吗?
Just stop the propagation here: 只需在此处停止传播:
$('.dropdown-toggle').click(function(event){
event.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.