如何启用bootstrap popover多次打开和关闭?

时间:2016-06-22 18:03:16

标签: javascript html twitter-bootstrap popover

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

我目前有以下实施方式:

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'
    });
});  

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

1 个答案:

答案 0 :(得分:2)

您可以通过添加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'
    });
});  
相关问题