javascript - HTML 未在弹出内容的 Bootstrap 中执行

标签 javascript jquery html twitter-bootstrap popover

我试图在弹出窗口内容中执行 HTML,但实际显示的是 HTML 代码而不是格式化文本。

HTML:

<li><a  id="pop1" class="icon-question-sign pop" href="player link" target="ifrm">player1</a></li>
<li><a  id="pop2" class="icon-question-sign pop" href="player link" target="ifrm">player2</a></li>

<div id="pop1_content" class="popSourceBlock">
<div class="popContent">
    <p>This is the content for the <strong>first</strong> player.</p>
</div>
</div>
<div id="pop2_content" class="popSourceBlock">
<div class="popContent">
    <p>This is the content for the <strong>second</strong> player.</p>
</div>

STYLE:
<style>
   .popSourceBlock {
    display:none;
  }
  </style>                

JAVASCRIPT CODE:

 <script>   
    $(".pop").each(function() {
    var $pElem= $(this);
   $pElem.popover(
        { trigger: "hover focus",
          HTML: true,
          content: getPopContent($pElem.attr("id"))
        }
    );
    });

    function getPopContent(target) {
        return $("#" + target + "_content > div.popContent").html();
    };
 </script>

我想看看:

这是第一个玩家的内容。

我实际得到的是:

< p>这是第一个玩家的内容。

我的最终目标是使用HTML代码来显示图片而不是文本。

最佳答案

这是因为您的 HTML 选项。

将其更改为小写,而不是大写。

<强> Bootply

JS:

   $(".pop").each(function() {
    var $pElem= $(this);
   $pElem.popover(
        { trigger: "hover focus",
          html: true,     //   <---------------  LOOK HERE
          content: getPopContent($pElem.attr("id"))
        }
    );
    });

    function getPopContent(target) {
        return $("#" + target + "_content > div.popContent").html();
    };

关于javascript - HTML 未在弹出内容的 Bootstrap 中执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24413456/

相关文章:

javascript - 需要让jquery将css添加到通过ajax添加的表中

javascript - 返回到动态大小页面上的滚动条位置

html - 如何在实时预览中突出显示元素后显示蓝色边框?

html - 每隔一个 div 后清除 float

javascript - 如何删除计算中的 NaN

javascript - Firebase Cloud Functions – JavaScript/Typescript Promisereject() 问题

javascript - 如何在next js中使用组件级sass文件

javascript - 在 AMD 文件中添加隐式依赖项

javascript - CSS 替代 CSS 加号选择器?

php - 使用 php 作为远程源的 Jquery 自动完成 : how to append second variable from input to source