我希望能够在弹出窗口外单击以使其消失。
这段代码运行良好-当一个弹出窗口打开时,关闭另一个弹出窗口,当然,当你再次点击按钮时,它会消失。
var $visiblePopover;
$('body').on('click', '[rel="popover"]', function() {
var $this = $(this);
// check if the one clicked is now shown
if ($this.data('popover').tip().hasClass('in')) {
// if another was showing, hide it
$visiblePopover && $visiblePopover.popover('hide');
// then store reference to current popover
$visiblePopover = $this;
} else { // if it was hidden, then nothing must be showing
$visiblePopover = '';
}
});我需要保持这个当前的功能,但修改它,使它做同样的事情时,你点击外弹出以及。
发布于 2013-04-23 02:20:32
您只需添加以下内容即可:
$('html').click(function(e) {
$('.btn').popover('hide');
});jsfiddle
发布于 2014-01-08 00:20:59
如果您想要关闭除已单击的弹出窗口之外的所有其他弹出窗口,则此小技巧非常方便:
$('.popover').click(function (evt) {
evt.stopPropagation();
$('.popover').not(this).popover('hide');
});发布于 2013-03-04 17:28:15
$.fn.modal.Constructor = Modal
$(function () {
$('body').on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
if($visiblePopover && $visiblePopover){
alert("HIDE POPOVER WHEN MODAL IS OPENED")
$visiblePopover && $visiblePopover.popover('hide');
}
var $this = $(this),
href = $this.attr('href'),
$target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))),
option = $target.data('modal') ? 'toggle' : $.extend({
remote: !/#/.test(href) && href
}, $target.data(), $this.data())
e.preventDefault()
$target.modal(option).one('hide', function () {
$this.focus()
})
})
})https://stackoverflow.com/questions/14894477
复制相似问题