单击外部以消除Bootstrap弹出窗口

问题描述:

如何通过在弹出窗口外单击来消除Bootstrap弹出窗口.目前,它具有打开链接的切换功能.

How to dismiss Bootstrap popover by clicking outside the popover. Currently it has toggle for open link.

HTML

 <div class="widget-rating">
          <span class="rateit rating-average"></span>
          <a class="btn btn-mini" href="javascript:void(0)"><b class="caret"></b></a>
 </div>

这是js代码

element.popoverAnchor.popover({
        title: "Rating",
        animation: false,
        html: true,
        content: "Loading...",
        placement: "bottom",
        trigger: "click"
      });

$('body').on('click', function (e) {
    $('.popover-link').each(function () {
        //the 'is' for buttons that trigger popups
        //the 'has' for icons within a button that triggers a popup
        if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
            $(this).popover('hide');
        }
    });
});

参考资料: http://mattlockyer.com/2013/04/08/close-a-twitter-bootstrap-popover-when-clicking-outside/