Bootstrap里怎么动态创建一个popover

2025-05-14 05:11:42
推荐回答(1个)
回答1:

Bootstrap里如何动态创建一个popover

一种简单的方法就是自己写 popover 的 html,并且在需要显示 popover 的地方控制内容变化。
$("#your-button").popover({
html: true,
content: '

...
'
})
.click(function() {
$("#content").text('YOUR CONTENT');
});

P.S. 最新的 bootstrap 3 的 popover(options) 初始化参数里提供了修改默认 popover template html 的选项,我没有实际用过不确定有没有坑,看起来会比上面的方法更加优雅。

js:





window.addEventListener("hashchange", function() { scrollBy(0, -145) })
$('#profil').popover({placement : 'bottom',html : 'true', trigger : 'hover'})

html: