在 Bootstrap Popover 中调用两次内容函数

Dan*_*rín 4 javascript jquery twitter-bootstrap bootstrap-popover

我有一个 Bootstrap Popover,它加载一个函数,如下所示:

var index = 0;

$('#Button').popover({
    html:true,
    placement:'right',
    content:function(){
      index = index +1;
      return index;
    }
});
Run Code Online (Sandbox Code Playgroud)

HTML 只是:

<input id="Button" value='popover' type='button'/>
Run Code Online (Sandbox Code Playgroud)

所以,当我点击按钮时,我应该得到 1、2、3 等......

但是,我得到 2,4,6... 因为它调用了“content”函数两次。这是为什么?这是一个错误还是我做错了什么?

这是小提琴

Ned*_*zić 5

这个问题不在您的代码中,而是来自引导程序本身。请参阅此链接: https ://github.com/twbs/bootstrap/issues/12563

所以,你可以在你身边修复它。设置一些标志来检查是否显示弹出窗口。