我们能得到弹窗被解雇的方式一样的情态动词,即。使他们关闭时,用户点击以外的地方?
不幸的是,我不能用真实的模态来代替弹窗,因为模态意味着位置:固定,那样就没有弹窗了。:(
我们能得到弹窗被解雇的方式一样的情态动词,即。使他们关闭时,用户点击以外的地方?
不幸的是,我不能用真实的模态来代替弹窗,因为模态意味着位置:固定,那样就没有弹窗了。:(
当前回答
只需将此属性添加到元素中
data-trigger="focus"
其他回答
这个问题之前已经被问到过了。我当时给出的答案仍然适用:
我也有类似的需求,并找到了这个很棒的小扩展的Twitter引导弹窗由李卡迈克尔,称为BootstrapX -点击。他还提供了一些用法示例。基本上,它会将弹出窗口更改为一个交互式组件,当您单击页面的其他地方或弹出窗口中的关闭按钮时,该组件将关闭。这也将允许多个弹窗一次打开和一堆其他不错的功能。
$('html').on('mouseup', function(e) {
if(!$(e.target).closest('.popover').length) {
$('.popover').each(function(){
$(this.previousSibling).popover('hide');
});
}
});
这将关闭所有弹出窗口,如果你点击任何地方,除了一个弹出窗口
更新引导4.1
$("html").on("mouseup", function (e) {
var l = $(e.target);
if (l[0].className.indexOf("popover") == -1) {
$(".popover").each(function () {
$(this).popover("hide");
});
}
});
这个派对来得太晚了……但我想分享一下 我喜欢弹窗,但是它的内置功能太少了。我写了一个引导扩展.bubble(),这就是我想要的弹窗的一切。四种解题方法。单击外部,切换链接,单击X,然后单击escape。
它会自动定位,所以永远不会离开页面。
https://github.com/Itumac/bootstrap-bubble
这不是毫无理由的自我推销……在我的生活中,我已经多次获得别人的代码,我想贡献我自己的努力。试一试,看看是否对你有用。
我试过很多以前的答案,真的没有一个对我有效,但这个解决方案管用:
https://getbootstrap.com/docs/3.3/javascript/#dismiss-on-next-click
他们建议使用锚标记而不是按钮,并注意role="button" + data-trigger="focus" + tabindex="0"属性。
Ex:
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-toggle="popover"
data-trigger="focus" title="Dismissible popover" data-content="amazing content">
Dismissible popover</a>
我有问题与mattdlockyer的解决方案,因为我设置弹窗链接动态使用如下代码:
$('body').popover({
selector : '[rel="popover"]'
});
所以我必须这样修改它。它为我解决了很多问题:
$('html').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('destroy');
}
});
});
记住destroy删除元素,所以选择器部分在初始化弹窗时很重要。