从这个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
}
});