Javascript 单击Popover触发器元素时,如何关闭/关闭引导Popover?
jsFiddle: 屏幕截图:Javascript 单击Popover触发器元素时,如何关闭/关闭引导Popover?,javascript,jquery,twitter-bootstrap,onclick,popover,Javascript,Jquery,Twitter Bootstrap,Onclick,Popover,jsFiddle: 屏幕截图: <button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button> <div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes insid
<button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
<div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
$('#popoverId').popover({
html: true,
title: 'Popover Title<a class="close" href="#");">×</a>',
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');
}
});
以下是有效的方法:
关闭弹出窗口。关闭按钮
<button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
<div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
$('#popoverId').popover({
html: true,
title: 'Popover Title<a class="close" href="#");">×</a>',
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');
}
});
单击以切换弹出窗口
这个丰富的html内容放在popover中
JS:
<button id="popoverId" class="popoverThis btn btn-large btn-danger">Click to toggle popover</button>
<div id="popoverContent" class="hide">This <em>rich</em> <pre>html</pre> content goes inside popover</div>
$('#popoverId').popover({
html: true,
title: 'Popover Title<a class="close" href="#");">×</a>',
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');
}
});
$('popoverId').popover({
是的,
标题:“Popover标题”,
内容:功能(){
返回$('popcovercontent').html();
}
});
var isVisible=false;
var clickedAway=false;
$('.popoverThis').popover({
是的,
触发器:“手动”
})。单击(功能(e){
$(this.popover('show');
$('.popover content')。追加('×;');
ClickedWay=false
isVisible=true
e、 预防默认值()
});
$(文档)。单击(函数(e){
如果(可见并单击路径){
$('.popoverThis').popover('hide'))
isVisible=ClickedWay=false
}否则{
ClickedWay=true
}
});
你想这样工作吗
$('popoverId').popover({
是的,
标题:“Popover标题”,
内容:$('#popoverContent').html(),
});
$(“#popoverId”)。单击(函数(e){
e、 停止传播();
});
$(文档)。单击(函数(e){
if($('.popover').has(e.target).length==0)| |$(e.target).is('.close')){
$('popoverId')。popover('hide');
}
});
我用这个:
<div id='content'>something here</div>
$('[data-toggle=popover]').popover({
html: true,
content: function () {
return $('#content').html();
}
}).click(function (e) {
$('[data-toggle=popover]').not(this).popover('hide');
});
只需使用此代码即可完成
这里有些东西
$('[data toggle=popover]')。popover({
是的,
内容:功能(){
返回$('#content').html();
}
})。单击(功能(e){
$('[data toggle=popover]')。而不是(this.popover('hide');
});
此简单代码将隐藏页面上的所有弹出窗口
$('.popover').popover('hide') 不,我不能让popover在任何地方点击就消失。popover应该只在(1)关闭、(2)在.popover外,(3)在原始按钮上关闭。你应该可以随意点击popover,而不必关闭它。就像这样:除非再次点击红色按钮,否则会关闭popover。很好。这很有效。。。除此之外,现在我每页只能有一个popover(除非我为每个popover添加stopPropagation)。为什么它不能只在类中工作?不管怎样,它可以完美地在多个按钮中工作。请参阅更新的JSFIDLE以了解如何将某些ID更改为类:@Ryan class.popover在哪里?我不懂这个密码