Bootstrap 3 popover显示一个并隐藏其他人不起作用

时间:2014-01-29 21:43:44

标签: javascript html css twitter-bootstrap popover

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;

}

我的页面中有这两个弹出框,当我点击其中一个,然后在第二个单击后,第一个弹出窗口隐藏,一切正常。但是,当我再次点击第一个弹出窗口后,它似乎无法正常工作。鼠标无法单击滚动,弹出窗口中的链接无法正常工作。我认为浏览器保持打开最后打开的弹出窗口,即使它是隐藏的。有什么建议吗?谢谢!

1 个答案:

答案 0 :(得分:2)

我解决了(感谢关于弹出窗口的另一篇文章)我添加此代码的问题:

// 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;
            }
        });