无论如何,在内部单击弹出窗口时,是否可以阻止其关闭?当我添加container
选项时会发生这种情况。
$('#share_form').popover({
'container': '#share_form',
'html': true,
'content': function() { return $('#popover_content').html(); },
'title': 'My Title',
'placement': 'bottom',
'viewport': 'body',
});
$(document).on('click', '#div_button', function(event)
{
event.preventDefault();
alert("Whent his is clicked, the popover closes :(");
});
<div id="popover_content" style="display:none;">
<div id="div_button">Click Me</div>
</div>
编辑:这就是我最终很好地工作的结果;
$('#popover_button').popover({
'trigger': 'manual',
'container': '#element', /* element that moves on resize like popover_button */
'html': true,
'content': function() { return $('#popover_content').html(); },
'placement': 'bottom',
'viewport': 'body'
});
$("#popover_button").click(function(e){$('#popover_button').popover('toggle');});
$(document).click(function(e){
//popover_element is just what was inside #popover_button
if(e.target.id !== "popover_element" && !$(event.target).hasClass('popover-content'))
$("#popover_button").popover('hide');
});
最佳答案
您可能需要对此进行一些调整:http://jsfiddle.net/6zcyfrqp/1/
的HTML
<button type="button" class="btn btn-default">Popover on right</button>
<div id="content" class="hidden">this is my awesome content
<br/>includes a
<button type="button" class="btn btn-default">save</button> button
</div>
JS
$(function () {
var options = {
content: function () {
return $("#content").html();
},
placement: "right",
container: "body",
toggle: "popover",
title: 'My Title',
html: true
};
$('.btn').popover(options);
});