1

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 中。

4

2 回答 2

1

这应该让你整理出来:

解码包含特殊 HTML 实体的字符串的正确方法是什么?

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

function htmlDecode(value) {
    return $("<textarea/>").html(value).text();
}
于 2015-07-27T13:59:33.643 回答
0

var 编码HTML = " &lt;ol style=&quot;color: rgb(34, 34, 34); font-family: arial, sans-serif;&quot;&gt;&lt;li class=&quot;mod&quot; style=&quot;&quot;&gt; &lt;div class=&quot;_oDd&quot; style=&quot;&quot;&gt;&lt;span class=&quot;_Tgc&quot; style=&quot;font-size: 16px;&quot;&gt;&lt;b&gt;Test data&lt;/b&gt; is &lt;b&gt;data&lt;/b&gt; which has been specifically identified for use in &lt;b&gt;tests&lt;/b&gt;, typically of a computer program. Some &lt;b&gt;data&lt;/b&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.&lt;/span&gt;&lt;/div&gt; &lt;/li&gt;&lt;/ol&gt;";

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

这也有效。

于 2015-07-27T13:59:39.517 回答