BootStrap3 keep the dropdown menu open after click on the item

后端 未结 3 570
别那么骄傲
别那么骄傲 2020-11-29 11:50

I\'m using bootstrap3.0, with it excellent drop-down menu.

If I click out side of the drop-down menu the menu will disappear, and this is quite right.

but

3条回答
  •  无人及你
    2020-11-29 12:26

    The accepted answer is very helpful. I want to provide another perspective - when a drop down menu should stay open when only certain items are clicked.

    // A utility for keeping a Bootstrap drop down menu open after a link is
    // clicked
    //
    // Usage:
    //
    //   
    
    $(".dropdown .dropdown-menu a").on("click", function(e) {
      var keepMenuOpen = $(this).data("keep-menu-open"),
          $dropdown = $(this).parents(".dropdown");
    
      $dropdown.data("keep-menu-open", keepMenuOpen);
    });
    
    $(".dropdown").on("hide.bs.dropdown", function(e) {
      var keepMenuOpen = $(this).data("keep-menu-open");
    
      $(this).removeData("keep-menu-open");
    
      return keepMenuOpen !== true;
    });
    

提交回复
热议问题