Rap*_*nah 6 html javascript css jquery twitter-bootstrap
正如你在jQuery中看到的那样,我已经使用了这个问题的答案来使一个Bootstrap Popover在外部点击时消失.现在我想在右上角添加一个"x",在点击时关闭弹出窗口.
有没有一种简单的方法可以在弹出窗口的右上角创建一个可点击的"x",当点击它时会关闭弹出窗口?
HTML:
<h3>Live demo</h3>
<div class="bs-docs-example" style="padding-bottom: 24px;">
<a href="#" class="btn btn-large btn-danger" data-toggle="popover" title="A Title" data-content="And here's some amazing content. It's very engaging. right?">Click to toggle popover</a>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
var isVisible = false;
var clickedAway = false;
$('.btn-danger').popover({
html: true,
trigger: 'manual'
}).click(function(e) {
$(this).popover('show');
clickedAway = false
isVisible = true
e.preventDefault()
});
$(document).click(function(e) {
if (isVisible & clickedAway) {
$('.btn-danger').popover('hide')
isVisible = clickedAway = false
} else {
clickedAway = true
}
});
Run Code Online (Sandbox Code Playgroud)
Cod*_*ist 16
这是jquery代码:
这个只是将X按钮添加到右上角:
var isVisible = false;
var clickedAway = false;
$('.btn-danger').popover({
html: true,
trigger: 'manual'
}).click(function(e) {
$(this).popover('show');
$('.popover-title').append('<button type="button" class="close">×</button>');
clickedAway = false
isVisible = true
e.preventDefault()
});
$(document).click(function(e) {
if(isVisible & clickedAway)
{
$('.btn-danger').popover('hide')
isVisible = clickedAway = false
}
else
{
clickedAway = true
}
});
Run Code Online (Sandbox Code Playgroud)
只有在单击X按钮时,才会关闭弹出窗口:
$('.btn-danger').popover({
html: true,
trigger: 'manual'
}).click(function(e) {
$(this).popover('show');
$('.popover-title').append('<button type="button" class="close">×</button>');
$('.close').click(function(e){
$('.btn-danger').popover('hide');
});
e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15888 次 |
| 最近记录: |