以可重用的方式指定弹出内容的另一种方法是创建一个新的data属性data-popover-content,如下所示:
HTML:
This is the heading for #1
This is the body for #1
JS:
$(function(){
$("[data-toggle=popover]").popover({
html : true,
content: function() {
var content = $(this).attr("data-popover-content");
return $(content).children(".popover-body").html();
},
title: function() {
var title = $(this).attr("data-popover-content");
return $(title).children(".popover-heading").html();
}
});
});
当您有很多HTML放置在弹出窗口中时,这很有用。
这是一个示例小提琴:http : //jsfiddle.net/z824fn6b/