jquery - 如何在 jquery 的 bootstrap popover 内容中放置一个字形图标

标签 jquery html css twitter-bootstrap glyphicons

我想在弹出窗口的内容旁边包含一个字形图标,它将在 jquery 中动态完成。 但是当我为字形图标添加 span 标签时,它会在显示弹出窗口时显示 html 字符串。它不会将其翻译成 html

$(this).attr("data-content", "<span class=\"glyphicon glyphicon-warning-sign\" aria-hidden=\"true\"></span>You can't unlist if you have upcoming events scheduled" );

内容最终在弹出窗口中看起来像这样

"<span class=\"glyphicon glyphicon-warning-sign\" aria-hidden=\"true\"></span>You can't unlist if you have upcoming events scheduled"

最佳答案

根据 Bootstrap 文档,如果您需要动态设置 data-content,则不应将其指定为属性。

试试这个,

HTML

<div class="container">
  <h3>Popover Example</h3>
  <a href="#" data-toggle="popover" title="Popover Header">Toggle popover</a>
</div>

JS

$(document).ready(function(){
    $('[data-toggle="popover"]').popover({
    html:true,
    content:function(){
    return ("<span class='glyphicon glyphicon-user'>Hello</span>");
    },
    });   
});

Working Fiddle

希望这有帮助..

关于jquery - 如何在 jquery 的 bootstrap popover 内容中放置一个字形图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45258766/

相关文章:

javascript - 在新展开的div中展开隐藏内容

javascript - 保留 dom 节点问题的未修改副本

javascript - 未捕获的 TypeError : $. tmpl 不是函数

html - 有没有办法在输入时自动扩展内容 block ?

javascript - 使用包含框架的 html 页面加载 Div

javascript - 淡出图像并替换为另外 5 个等等?

javascript - 只显示特定的json信息

javascript - 如何在 HTML 5 Canvas 中添加可选文本?

css - 相同的样式表在浏览器和存储它的服务器上显示不同

html - 为什么边框宽度和我在html中设置的不一样?