简体   繁体   中英

hide dropdown menu on click the item in the menu

I have five buttons, for each button, if you mouseover it, it will popup the dropdown menu (The default setting in bootstrap for dropdown is to click, but I need the button to achieve some other purposes when click the button, so I use a e.stopPropagation() to prevent the click popup action). In the css file, I set

.dropup:hover .dropdown-menu {
    display: block;
}

My question is that, when I click the item in the dropdown menu, it will not hide anymore. Is there anyway to solve this issue?

Could you do something like this in place of your css so you don't have to rewrite functionality?

$(function() {
    $(".dropdown").hover(
        function(){ $(this).addClass('open') },
        function(){ $(this).removeClass('open') }
    );
});

Reference: https://stackoverflow.com/a/21486327/1585362

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM