单击外部以消除Bootstrap弹出窗口 [英] Dismiss Bootstrap popover by clicking outside

查看:83
本文介绍了单击外部以消除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/

这篇关于单击外部以消除Bootstrap弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆