[英]Hide dropdown menu when clicked - Bootstrap
I have a navigation bar in my website and all the links are loading a content in a container through AJAX. 我的网站上有一个导航栏,所有链接都通过AJAX将内容加载到容器中。
Now, I need to hide the dropdown menu when a link is clicked. 现在,我需要在单击链接时隐藏下拉菜单。 That's not the normal behavior of bootstrap.
这不是引导程序的正常行为。
Here's my code in the fiddle. 这是我的小提琴代码。
$(".dropdown-menu a").click(function() { $(this).closest(".dropdown-menu").prev().toggle(); });
http://jsfiddle.net/fw7vh/158/ http://jsfiddle.net/fw7vh/158/
I recently browsed into existing answers but it removes the dropdown button. 我最近浏览了现有答案,但删除了下拉按钮。 Please advise.
请指教。 Thanks!
谢谢!
Try with: 尝试:
$(".dropdown-menu a").click(function() {
var menu = $(this).closest(".dropdown-menu");
$(menu).css('display','none');
setTimeout(function(){
$(menu).css('display','');
},200);
});
If I understood your question correctly, this might help you. 如果我正确理解了您的问题,这可能会对您有所帮助。
$(".dropdown-menu a").click(function() {
$(this).closest(".dropdown-menu").toggle();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.