gpt4 book ai didi

javascript - 将特殊字符转换为 HTML

转载 作者:行者123 更新时间:2023-11-29 21:58:10 25 4
gpt4 key购买 nike

$scope.html = '<script>';

我知道PHP有转换&lt;script&gt;的能力至 <script>但 Javascript 也能做到吗?

最佳答案

使用这个有效

function escapeSpecialChars(text) {
return text
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, "\"")
.replace(/&#039;/g, "'");
}

关于javascript - 将特殊字符转换为 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25361032/

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