[英]Bootstrap 3 popover show one and hide others doesn't work
HTML
<ul class="navbar-nav pull-right">
<li><a href="#" data-toggle="popover" title="Notifiche" data-html="true" data-content="Notification1<hr />Notification 2<hr />Notification 3">Notifications</a></li>
<li><a href="#" data-toggle="popover" title="Messages" data-html="true" data-content="Message 1<hr />Message 2<hr />Message 3">Messages</a></li>
</ul>
JAVASCRIPT
$('[data-toggle="popover"]').popover({placement: 'bottom', trigger: 'click' });
//hide popover when click outside
$('body').on('click', function (e) {
$('[data-toggle="popover"]').each(function () {
if ($(this).has(e.target).length === 0 && $('.popoVer').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
CSS
.popover-content {
max-height: 150px;
overflow-y: scroll;
}
我的页面中有这两个弹出窗口,当我单击其中的一个,然后单击第二个之后,第一个弹出窗口就会隐藏起来,并且一切正常。 但是当我再次单击第一个弹出窗口后,似乎无法正常工作。 鼠标无法在滚动条中单击,并且弹出窗口中的链接无法正常工作。 我认为浏览器将保持打开的最后一个弹出窗口,即使它是隐藏的。 有什么建议吗? 谢谢!
我解决了此问题(由于有关弹出窗口的另一篇文章),添加了以下代码:
// hide other popovers (and their links from the DOM) opened
$(document).mouseup(function (e) {
if ($('.popover').has(e.target).length === 0) {
$('.popover').toggleClass('in').remove();
return;
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.