我的页面上有很多弹出窗口,我想通过单击下一个弹出窗口来关闭上一个打开的弹出窗口。
它起作用了!但是,当我再次点击前一个波波弗,我必须点击两次!
我也希望通过点击外部关闭罂粟。
$('.triggerOverlay').popover({
html : true,
content: function() {
var $this = $(this);
var cont = $this.data('toggle');
return $('#'+cont).html();
}});关闭除当前以外的所有弹出窗口的下列代码
$('.triggerOverlay').on('click', function (e) {
$('.triggerOverlay').not(this).popover('hide');
});Fiddle
发布于 2015-12-02 21:10:04
这应该能行。将click事件侦听器添加到文档中,并始终隐藏弹出框。
如果事件目标是带有弹出器的锚标记之一,则切换它。还将trigger属性添加到设置为manual的popover选项中。
$( document ).ready(function() {
$('.triggerOverlay').popover({
html : true,
content: function() {
var $this = $(this);
var cont = $this.data('toggle');
return $('#'+cont).html();
},
trigger: 'manual'
});
$(document).on('click', function (e) {
// always hide them all.
$('.triggerOverlay').popover('hide');
// if e.target has a popover toggle it.
if ($(e.target).hasClass('triggerOverlay')) {
$(e.target).popover('toggle');
}
});
});.customoverlay{display:none;}<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<a href="#" data-toggle="user-profile-overlay" class="triggerOverlay">button</a><br><br><br><br><br>
<div id="user-profile-overlay" class="customoverlay">content goes here</div>
<a href="#" data-toggle="user-profile-overlay1" class="triggerOverlay">button</a><br><br><br><br>
<div id="user-profile-overlay1" class="customoverlay">second content goes here</div>
<a href="#" data-toggle="user-profile-overlay2" class="triggerOverlay">button</a><br><br><br>
<div id="user-profile-overlay2" class="customoverlay">third content goes here</div>
https://stackoverflow.com/questions/34051828
复制相似问题