简体   繁体   English

如何防止bootstrap下拉子菜单单击关闭父下拉列表

[英]How to prevent bootstrap dropdown submenu click closing the parent dropdown

I have a dropdown that contains a div which contains a dropdown of its own. 我有一个包含div的下拉列表,其中包含自己的下拉列表。 As soon as I click the inner dropdown, the parent dropdown closes. 单击内部下拉列表后,父下拉菜单将关闭。 How to prevent the parent dropdown from closing ? 如何防止父下拉关闭? And how to solve the same problem for multiple nested dropdowns ? 以及如何为多个嵌套下拉列表解决同样的问题? Code: 码:

<div class="dropdown selectDropdownDiv">
  <a data-toggle="dropdown" href="#" class="btn selectDropdown">--<span class="caret pull-right"></span></a>
  <div class="dropdown-menu keep_open" role="menu" aria-labelledby="dLabel" id="keywordDropdown">
    <div class="dropdown selectDropdownDiv">
      <a data-toggle="dropdown" href="#" class="btn selectDropdown">--<span class="caret pull-right"></span></a>
      <ul class="dropdown-menu keep_open" role="menu" aria-labelledby="dLabel">
        <li class="checkbox marginl5">
          <label>
            <span class="checkLabel">Source X</span><input type="checkbox">
          </label>
        </li>
        <li class="checkbox marginl5">
          <label>
            <span class="checkLabel">Source X</span><input type="checkbox">
          </label>
        </li>
      </ul>
    </div>
  </div>
</div>

I am using Twitter Bootstrap. 我正在使用Twitter Bootstrap。 Any help would be appreciated. 任何帮助,将不胜感激。

This should work. 这应该工作。 It stop the propagation of the click event to the bootstrap event that controls hiding the menu. 它会停止将click事件传播到控制隐藏菜单的引导事件。

$("#parent-element").on("click", ".dropdown-menu", function (e) {
    $(this).parent().is(".open") && e.stopPropagation();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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