读取html内容而不转义?

发布于 2025-01-19 20:12:31 字数 108 浏览 2 评论 0原文

我正在尝试使用InnerHTML读取HTML内容。它似乎转换了'<'在'& lt的文本内容中;' 。

我宁愿不这样做。 JS中有什么可以让我这样渲染

I am trying to read the html content using innerHTML. It seems to convert the '<' in the text content to '<' .

I would rather not to. Is there anything in JS that would allow me to render as such

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2025-01-26 20:12:31

Lodash 支持执行此操作的 unescape() 函数

例如,

// This reads < as <
let html = document.querySelector('.el').innerHTML
// This converts the < back into <
html = _.unescape(html)

此问题中提供了更多答案:在 JavaScript 中取消转义 HTML 实体?

Lodash supports an unescape() function that does this.

For example,

// This reads < as <
let html = document.querySelector('.el').innerHTML
// This converts the < back into <
html = _.unescape(html)

More answers are available in this question: Unescape HTML entities in JavaScript?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文