【问题标题】:How to change html shorthand to html tag when adding content dynamically动态添加内容时如何将html简写更改为html标签
【发布时间】:2015-07-27 13:49:52
【问题描述】:

var encodedHtml = "<ol style="color: rgb(34, 34, 34); font-family: arial, sans-serif;"><li class="mod" style=""> <div class="_oDd" style=""><span class="_Tgc" style="font-size: 16px;"><b>Test data</b> is <b>data</b>

已被明确标识用于<b>tests</b>,通常用于计算机程序。一些<b>data</b> 可以用于确认方式,通常用于验证给定函数的一组给定输入是否产生了一些预期结果。</span></div> </li></ol>";

我想将此内容更改为html标签,因此我可以使用js将其添加到某些div中。

【问题讨论】:

    标签: javascript jquery dynamic-html


    【解决方案1】:

    这应该会让你解决问题:

    What's the right way to decode a string that has special HTML entities in it?

    下面的几个答案它有一个 jQuery 版本:

    function htmlDecode(value) {
        return $("<textarea/>").html(value).text();
    }
    

    【讨论】:

      【解决方案2】:

      var encodedHTML = "&amp;lt;ol style=&amp;quot;color: rgb(34, 34, 34); font-family: arial, sans-serif;&amp;quot;&amp;gt;&amp;lt;li class=&amp;quot;mod&amp;quot; style=&amp;quot;&amp;quot;&amp;gt; &amp;lt;div class=&amp;quot;_oDd&amp;quot; style=&amp;quot;&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;_Tgc&amp;quot; style=&amp;quot;font-size: 16px;&amp;quot;&amp;gt;&amp;lt;b&amp;gt;Test data&amp;lt;/b&amp;gt; is &amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; which has been specifically identified for use in &amp;lt;b&amp;gt;tests&amp;lt;/b&amp;gt;, typically of a computer program. Some &amp;lt;b&amp;gt;data&amp;lt;/b&amp;gt; may be used in a confirmatory way, typically to verify that a given set of input to a given function produces some expected result.&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt; &amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;";

      $("<p/>").html(encodedHTML ).text();
      

      这也有效。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-29
        • 1970-01-01
        • 2014-08-30
        • 1970-01-01
        相关资源
        最近更新 更多