有人知道我如何通过JavaScript/jquery创建和添加数据到bootstrap 5 popover吗?
在Bootstrap 3中,我可以做到这一点:
$('#element').popover({ placement : 'left', trigger : 'focus', html: true });
let content_template = `<h1>Hello World!</h1>`;
$('#element').data('bs.popover').options.content = content_template;
但我不知道我怎么能用bootstrap 5做同样的事情。文件上没有提到这一点。有谁知道在BS 5中如何管理Popovers?
4条答案
按热度按时间flvlnr441#
您需要获取弹出框的示例,然后使用
popover_instance._config.content ="some message"
在弹出框中设置新内容。eufgjt7s2#
使用vanilla JavaScript而不是jQuery。popover示例从示例化返回。然后,您可以使用它来修改内容...
Demo
prdp8dxp3#
如果您计划多次更新弹出框内容,则还需要在弹出框示例上调用
setContent()
。这样42fyovps4#
您需要获取popover的示例并使用
setContent
方法(请参阅文档https://getbootstrap.com/docs/5.3/components/popovers/#methods)setContent
方法的唯一参数是具有以下格式的对象