简体   繁体   English

单击列表时,使用bootstrapDropdown防止Dropdown菜单消失

[英]Prevent the disappear of Dropdown menu using bootstrapDropdown when clicking on the list

I am using using bootstrap-dropdown to generate a Dropdown menu. 我正在使用bootstrap-dropdown生成下拉菜单。 I would like to prevent the disappearing of the menu when click on it. 我想在点击它时防止菜单消失。

I have implemented the following code, but it does not work. 我已经实现了以下代码,但它不起作用。 Any idea how to fix it? 知道怎么解决吗?

HTML HTML

<li class="dropdown notification">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown">
    <span class="notification-label label label-info">
      <i class="icon-inbox icon-white"></i>
      <span class="notification-number">{{ unread_notifications }}</span>
    </span>
  </a>
  <ul class="dropdown-menu notification-list"></ul>
</li>

JS JS

events: {
  'click ul.notification-list': 'onClickNotification'
},

onClickNotification: function (e) {
  e.preventDefault();
  console.log(e);
},

Did you try with event.stopPropagation ? 你尝试过event.stopPropagation吗?

onClickNotification: function (e) {
    e.stopPropagation();
    console.log(e)
},

If you want to disable all auto closing of the dropdown you can just disable the listener 如果要禁用所有自动关闭下拉列表,只需禁用侦听器即可

$('html').off('click.dropdown')

JSFiddle 的jsfiddle

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

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