如何在JS中取消对HTML实体的转义? (将& lt;更改为<) [英] How do i unescape HTML Entities in JS? (change < to <)

查看:102
本文介绍了如何在JS中取消对HTML实体的转义? (将& lt;更改为<)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JS中取消对HTML实体的转义?

在谷歌搜索时,我从字面上看到了答案,并且做出了巨大的选择,人们纷纷滚动.

我希望字符串&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;成为<html xmlns="http://www.w3.org/1999/xhtml" >

解决方案

创建div,将其设置为innerHTML,然后阅读innerText

var d = document.createElement("div");
d.innerHTML = "&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;";
alert(d.innerText || d.text || d.textContent);

How do i unescape HTML Entities in JS?

When googling i literally saw answers with a huge switch and people rolling their own.

I'd like the string &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt; to become <html xmlns="http://www.w3.org/1999/xhtml" >

解决方案

Create a div, set it's innerHTML and then read innerText

var d = document.createElement("div");
d.innerHTML = "&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;";
alert(d.innerText || d.text || d.textContent);

这篇关于如何在JS中取消对HTML实体的转义? (将&amp; lt;更改为&lt;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆