Bootstrap dropdown checkbox select

前端 未结 3 434
醉酒成梦
醉酒成梦 2020-12-14 02:05

I\'m trying to customize a bootstrap dropdown with checkboxes and if I select a checkbox from dropdown the label name I want to be written on input dropdown delimited with \

3条回答
  •  情深已故
    2020-12-14 02:48

    The following code works in Bootstrap 4.1 if you add a function to show the menu on hover, but when you click the < li > then your checkboxes becomes unclickable. Anybody having a better solution please provide.

    
    

    And add these JS codes:

    // Allow Bootstrap dropdown menus to have forms/checkboxes inside, 
    // and when clicking on a dropdown item, the menu doesn't disappear.
    $(document).on('click', '.dropdown-menu.dropdown-menu-form', function(e) {
      e.stopPropagation();
    });
    

    UPDATE

    The below code is working good but checkboxes events are fired twice so had to choose the onchange event instead of onclick

    
    

    and the jquery code as follows:

    $(document).on('click', '.dropdown-menu', function (e) {
        e.stopPropagation();
    });
    

提交回复
热议问题