简体   繁体   中英

Bootstrap, how to prevent from closing a dropdown-menu when modal popup displayed

Inside a dropdown-menu I have a button to open a modal popup. If you display the modal popup when you close it, it will also close the dropdown-menu.

How to prevent from closing a dropdown-menu when a modal popup is displayed ?

This is the code :

 <div class="dropdown-menu" style="width:240px;">

   <div class="row">
      <div class="col-xs-6">Log in</div>
      <div class="col-xs-6"><img data-toggle="modal" data-target="#myModal" width="20px" src="images/help-question.png"></div>
  </div>
...
</div>
  <div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">

   etc...

</div>

ok, I have found a solution :)

  var hideLogin = true ;
  $('#ModalHelpLogin').on('shown.bs.modal', function (e) {
    hideLogin = false ;
  })
  $('#ModalHelpLogin').on('hidden.bs.modal', function (e) {
    hideLogin = true ;
  })

  $('#DropLogin').on('hide.bs.dropdown', function () {
    return hideLogin ;
  }); 

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