Bootstrap Popover 在点击外部时不会关闭 [英] Bootstrap Popover Doesn't Close on Clicking Outside

查看:69
本文介绍了Bootstrap Popover 在点击外部时不会关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了有关如何在单击外部任意位置时关闭 Bootstrap Popover 的解决方案,https://stackoverflow.com/a/14857326/1005607

I followed this solution on how to close a Bootstrap Popover when clicking anywhere outside, https://stackoverflow.com/a/14857326/1005607

$('body').on('click', function (e) {
    //only buttons
    if ($(e.target).data('toggle') !== 'popover'
        && $(e.target).parents('.popover.in').length === 0) { 
        $('[data-toggle="popover"]').popover('hide');
    }
});

但是有些东西还是不行,我的 JSFiddle:https://jsfiddle.net/m2k0wgys/3/

But something still doesn't work, my JSFiddle: https://jsfiddle.net/m2k0wgys/3/

在此 JSFiddle 中,单击外部不会关闭 Popover.我的 Popovers 嵌套在 A-links 内.示例格式:

In this JSFiddle, clicking outside doesn't close the Popover. My Popovers are nested inside A-links. Sample format:

<a href="..>
   <input type="image" src="info.png" data-toggle="popover" data-content=".." />
</a>

推荐答案

对于仅包含文本的按钮:

For buttons containing text only:

$('body').on('click', function (e) {
//did not click a popover toggle or popover
if ($(e.target).data('toggle') !== 'popover'
    && $(e.target).parents('.popover.in').length === 0) { 
    $('[data-toggle="popover"]').popover('hide');
}

});

检查 stackoverflow 链接 输入链接描述在这里

check the stackoverflow link enter link description here

这篇关于Bootstrap Popover 在点击外部时不会关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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