javascript 我如何在 JS 中取消转义 HTML 实体?(将 < 改为 <)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/4480757/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do i unescape HTML Entities in JS? (change < to <)
提问by Sky Sanders
How do i unescape HTML Entities in JS?
我如何在 JS 中取消转义 HTML 实体?
When googling i literally saw answers with a huge switch and people rolling their own.
在谷歌搜索时,我确实看到了一个巨大的开关和人们自己滚动的答案。
I'd like the string <html xmlns="http://www.w3.org/1999/xhtml" >to become <html xmlns="http://www.w3.org/1999/xhtml" >
我希望字符串<html xmlns="http://www.w3.org/1999/xhtml" >变成<html xmlns="http://www.w3.org/1999/xhtml" >
回答by Sky Sanders
Create a div, set it's innerHTMLand then read innerText
创建一个div,设置它innerHTML然后读取innerText
var d = document.createElement("div");
d.innerHTML = "<html xmlns="http://www.w3.org/1999/xhtml" >";
alert(d.innerText || d.text || d.textContent);
回答by Samuel
Here is a JS implementation of a PHP function that decodes HTML entities
这是一个解码 HTML 实体的 PHP 函数的 JS 实现
http://phpjs.org/functions/html_entity_decode
http://phpjs.org/functions/html_entity_decode
Note that this function also depends on:
请注意,此功能还取决于:

