</img> 最佳答-6ren">
gpt4 book ai didi

javascript - 在元素内用 < 替换 <

转载 作者:行者123 更新时间:2023-11-29 16:24:05 25 4
gpt4 key购买 nike

如果一个html是

<pre>
<img src="imagesrc"></img>
</pre>

您将如何使用 jQuery 或 javascript 替换 <&lt;对于 <pre> 内的任何内容上面代码的输出应该是。

<pre>
&lt;img src="imagesrc">&lt;/img>
</pre>

最佳答案

你可能想要 HtmlEncode and HtmlDecode

function htmlEncode(value){
return $('<div/>').text(value).html();
}

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

关于javascript - 在元素内用 < 替换 <,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7973191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com