我正在使用bootstrap-dropdown生成下拉菜单。我想在点击它时防止菜单消失。
我已经实现了以下代码,但它不起作用。知道怎么解决吗?
<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>
events: {
'click ul.notification-list': 'onClickNotification'
},
onClickNotification: function (e) {
e.preventDefault();
console.log(e);
},
答案 0 :(得分:7)
您是否尝试使用event.stopPropagation
?
onClickNotification: function (e) {
e.stopPropagation();
console.log(e)
},
答案 1 :(得分:2)