Bootstrap popover,隐藏在外部? [英] Bootstrap popover, hide on click outside?
本文介绍了Bootstrap popover,隐藏在外部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用bootstrap popover,现在我试图使此代码在popover外部单击以关闭popover:
using bootstrap popover, and now im trying to get this code to click outside the popover to close the popover:
$('body').on('click', function (e) {
$('[data-toggle="popover"]').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');
}
});
});
但是当我使用这部分时,我可以关闭弹出窗口,但是我不能单击其他按钮,任何人都知道我该怎么做?
But when i use this part, i can close the popover but i cant click the other buttons, anyone got any idea how i can do that?
所有按钮:
<a href="#" class="btn btn-xs btn-primary" data-toggle="popover">This opens popover</a>
<a href="#" class="btn btn-xs btn-primary">Other link</a> <- Doesn't work
<a href="#" class="btn btn-xs btn-primary">Other link</a> <- Doesn't work
推荐答案
我发现了这个问题: http://bootply.com/99372
$('body').on('click', function (e) {
$('[data-toggle=popover]').each(function () {
// hide any open popovers when the anywhere else in the body is clicked
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
}
});
});
与您的代码几乎相同...
It's almost the same code as you...
这篇关于Bootstrap popover,隐藏在外部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文