admin管理员组

文章数量:1292360

I am using using bootstrap-dropdown to generate a Dropdown menu. 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

<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

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

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

I am using using bootstrap-dropdown to generate a Dropdown menu. 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

<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

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

onClickNotification: function (e) {
  e.preventDefault();
  console.log(e);
},
Share edited Jul 31, 2012 at 15:10 merv 77.1k17 gold badges214 silver badges277 bronze badges asked Jul 31, 2012 at 15:03 Lorraine BernardLorraine Bernard 13.4k23 gold badges85 silver badges138 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Did you try with 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

本文标签: