jsFiddle:http://jsfiddle.net/kAYyR/
截图:
这是有效的:
- 点击按钮打开弹出框
- 在弹出框外点击关闭弹出框
- 点击
.close
按钮关闭弹出窗口
但是...当您再次单击原始按钮时,我无法关闭弹出窗口。取而代之的是,弹出窗口会闪烁,然后再次闪烁。
自己复制đây .
Làm thế nào tôi có thể làm điều này?
HTML:
This
rich html
content goes inside popover
JS:
$('#popoverId').popover({
html: true,
title: "Popover Title",
content: function () {
return $('#popoverContent').html();
}
});
var isVisible = false;
var clickedAway = false;
$('.popoverThis').popover({
html: true,
trigger: 'manual'
}).click(function (e) {
$(this).popover('show');
$('.popover-content').append('×');
clickedAway = false
isVisible = true
e.preventDefault()
});
$(document).click(function (e) {
if (isVisible & clickedAway) {
$('.popoverThis').popover('hide')
isVisible = clickedAway = false
} khác {
clickedAway = true
}
});
你想要这样的工作吗?
http://jsfiddle.net/kAYyR/3/
$('#popoverId').popover({
html: true,
title: 'Popover Title×',
content: $('#popoverContent').html(),
});
$('#popoverId').click(function (e) {
e.stopPropagation();
});
$(document).click(function (e) {
if (($('.popover').has(e.target).length == 0) || $(e.target).is('.close')) {
$('#popoverId').popover('hide');
}
});
Tôi là một lập trình viên xuất sắc, rất giỏi!