Keep Bootstrap Dropdown open in Navbar no matter what

后端 未结 2 1431
耶瑟儿~
耶瑟儿~ 2021-01-18 21:07

I have a dropdown menu nested in a navbar that I am opening during page load by adding the open class to the li element containing the dropdown men

2条回答
  •  温柔的废话
    2021-01-18 21:28

    I am assuming that you are using a bootstrap dropdown, give this a shot:

    $('li.dropdown').on({
        "shown.bs.dropdown": function() { this.close = false; },
        "click":             function() { this.close = true; },
        "hide.bs.dropdown":  function() { return this.close; }
    });
    

    The above implementation will hide the dropdown when it is clicked again. If you do not like that behavior, you can simply remove the first two lines (shown.bs.dropdown and click events) and simply return false for hide.bs.dropdown event.

    Here is working proof bootply

    Here is a working proof bootply that will always stay open

提交回复
热议问题