如何在动态添加内容时将html shorthand 更改为html 标签
How to change html shorthand to html tag when adding content dynamically
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。
这应该可以帮助您解决问题:
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();
}
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> which has been specifically identified for use in <b>tests</b>, typically of a computer program. Some <b>data</b> may be used in a confirmatory way, typically to verify that a given set of input to a given function produces some expected result.</span></div> </li></ol>
";
$("<p/>").html(encodedHTML ).text();
这也行。
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。
这应该可以帮助您解决问题:
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();
}
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> which has been specifically identified for use in <b>tests</b>, typically of a computer program. Some <b>data</b> may be used in a confirmatory way, typically to verify that a given set of input to a given function produces some expected result.</span></div> </li></ol>
";
$("<p/>").html(encodedHTML ).text();
这也行。