jquery – 使用AJAX加载Bootstrap popover内容 这可能吗?

我尝试的适当位是这里:

<a href="#" data-content="<div id='my_popover'></div>"> Click here </a>

$(".button").popover({html: true})

$(".button").click(function(){
    $(this).popover('show');
    $("#my_popover").load('my_stuff')
})

当我点击,我看到请求得到,但不填充popover。我甚至不看到HTML的popover被添加到DOM,但这可能是firebug。

有没有人试过这个?

最佳答案
查看我的博客文章的工作解决方案:http://www.cagataygurturk.com/load-a-bootstrap-popover-content-with-ajax.html

First we should add a data-poload attribute to the elements you would
like to add a pop over to. The content of this attribute should be the
url to be loaded (absolute or relative):

<a href="#" title="blabla" data-poload="/test.php">blabla</a>

And in JavaScript, preferably in a $(document).ready();

$('*[data-poload]').hover(function() {
    var e=$(this);
    e.off('hover');
    $.get(e.data('poload'),function(d) {
        e.popover({content: d}).popover('show');
    });
});

off('hover') prevents loading data more than once and popover() binds
a new hover event. If you want the data to be refreshed at every hover
event, you should remove the off.

Please see the working 07001 of the example.

转载注明原文:jquery – 使用AJAX加载Bootstrap popover内容 这可能吗? - 代码日志