如何使bootstrap弹窗多次打开和关闭?

How to enable bootstrap popover to open and close multiple times?

我想要一个使用 bootstrap 的弹出窗口,可以通过单击弹出窗口中的按钮将其关闭。但是我关闭后,我必须在按钮上单击两次才能再次打开弹出窗口。

我目前有以下实现:

HTML:

<button type="button" id="example" class="btn btn-primary">example</button>

JAVASCRIPT:

$(document).ready(function() {
    $("#example").popover({
        placement: 'bottom',
        html: 'true',
        title : '<span class="text-info"><strong>Title</strong></span>'+
                '<button type="button" id="close" class="close"
                 onclick="$(&quot;#example&quot;).popover(&quot;hide&quot;);
                 ">&times;</button>',
        content : 'Content'
    });
});  

如何在弹出窗口中实现关闭按钮,而无需在按钮上单击两次以重新打开弹出窗口?

您可以通过添加 click() 事件来解决此问题。

$(document).ready(function() {
    $("#example").popover({
        placement: 'bottom',
        html: 'true',
        title : '<span class="text-info"><strong>Title</strong></span>'+
                '<button type="button" id="close" class="close"
                 onclick="$(&quot;#example&quot;).popover(&quot;hide&quot;).click();
                 ">&times;</button>',
        content : 'Content'
    });
});