从这个jsFiddle可以看出,我有一个Boostrap Popover,可以通过外部点击关闭,也可以点击“x”。
但是,当您单击另一个按钮弹出窗口时,第一个弹出窗口不会消失。
有没有办法更改javascript,以便第一个弹出消息在任何点击时消失?
HTML:
<form action="quote-calculator.php" method="post">
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="more-info btn btn-large btn-danger" data-toggle="popover" data-content="And here's some amazing content. It's very engaging. right?">Click to toggle popover</a>
</div>
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="more-info btn btn-large btn-danger" data-toggle="popover" data-content="And here's some amazing content. It's very engaging. right?">Click to toggle popover</a>
</div>
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="more-info btn btn-large btn-danger" data-toggle="popover" data-content="And here's some amazing content. It's very engaging. right?">Click to toggle popover</a>
</div>
</form>
jQuery的:
var isVisible = false;
var clickedAway = false;
$('.btn-danger').popover({
html: true,
trigger: 'manual'
}).click(function(e) {
$(this).popover('show');
$('.popover-content').append('<button class="close" style="position: absolute; top: 0; right: 6px;">×</button>');
clickedAway = false
isVisible = true
e.preventDefault()
});
$(document).click(function(e) {
if(isVisible & clickedAway)
{
$('.btn-danger').popover('hide')
isVisible = clickedAway = false
}
else
{
clickedAway = true
}
});
答案 0 :(得分:1)
答案 1 :(得分:1)
添加
$('.popover').hide();
前
$(this).popover('show');
这会隐藏所有popover
类元素,然后再显示当前元素。