简体   繁体   English

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

[英]Bootstrap 3 popover show one and hide others doesn't work

HTML 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 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 CSS

.popover-content {
max-height: 150px;
overflow-y: scroll;

} }

I have these two popovers in my page, and when i click in one of this, and after i click in the second, the first popover hides, and everything works fine. 我的页面中有这两个弹出窗口,当我单击其中的一个,然后单击第二个之后,第一个弹出窗口就会隐藏起来,并且一切正常。 But when i after click again on the first popover, it seems doesn't work properly. 但是当我再次单击第一个弹出窗口后,似乎无法正常工作。 The mouse can not click in the scroll, and the links in the popover don't work fine. 鼠标无法在滚动条中单击,并且弹出窗口中的链接无法正常工作。 I think the browser is holding open the last opened popover, even if it is hide. 我认为浏览器将保持打开的最后一个弹出窗口,即使它是隐藏的。 Any suggestion? 有什么建议吗? Thanks! 谢谢!

I solved (thanks to another post on popovers) my problem adding this code: 我解决了此问题(由于有关弹出窗口的另一篇文章),添加了以下代码:

// 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.

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