twitter-bootstrap Bootstrap popover.toggle() 只显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19974559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bootstrap popover.toggle() only show
提问by Jérémy Dutheil
I am trying to integrate a twitter bootstrap popover ; I am forced to use the javascript API, because some dynamic elements are loaded via Ajax and should react too.
我正在尝试集成 twitter bootstrap popover ;我被迫使用 javascript API,因为一些动态元素是通过 Ajax 加载的,也应该做出反应。
Basically, here is a example tag that should react :
基本上,这是一个应该做出反应的示例标签:
<a data-container="#appConfigDialog" data-toggle="popover" data-placement="top"
data-content="<img src="URL" />"
data-html="true" href="#"
class="popoverFileSee btn btn-default">See</a>
URL is by the way replaced by the correct URL
URL 顺便替换为正确的 URL
And my JS :
还有我的 JS:
$( document ).on( "click", ".popoverFileSee", function() {
$( this ).popover( "toggle" );
return false;
});
Here is the behavior I would like to achieve :
这是我想要实现的行为:
- When first click, the popover shows
- When a click occurs for an opened popover, it should close it
- 第一次点击时,弹出框显示
- 当一个打开的弹出框发生点击时,它应该关闭它
Isn't it the aim of "toggle" ? Is there something wrong in this code sample, or should I check elsewhere in my application ?
这不就是“切换”的目的吗?此代码示例中是否有问题,或者我应该检查应用程序中的其他地方吗?
Thanks
谢谢
EDIT : For now, it always show the popover, even if it is already opened
Weird thing : if I add alert( "test" );in my callback function, then it works..
编辑:现在,它总是显示弹出窗口,即使它已经打开 奇怪的事情:如果我添加alert( "test" );我的回调函数,那么它就可以工作..
回答by Jérémy Dutheil
Finally found the answer myself.. ;)
I simply had to add an attribute to my link : data-trigger="manual"
终于自己找到了答案.. ;) 我只需要在我的链接中添加一个属性: data-trigger="manual"
回答by Rohan Kumar
Removethe togglefrom popover functionwithout using click eventlike,
Remove在toggle从popover function没有使用click event等,
$(".popoverFileSee").popover();
Updated,If you need to add click eventthe after this you can add which is independentto popoverlike,
更新,如果您需要add click event在此之后,你可以添加它independent到popover喜欢,
$(".popoverFileSee").popover();
$(".popoverFileSee").on('click',function(){
// your ajax code here
});

