javascript 如何将 html 特殊字符转换为普通 HTML?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11848726/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 14:33:05  来源:igfitidea点击:

How to convert html special chars to ordinary HTML?

javascriptjqueryhtmlhtmlspecialchars

提问by Ivan Gromov

Possible Duplicate:
How to decode HTML entities using jQuery?
HtmlSpecialChars equivalent in Javascript?

可能的重复:
如何使用 jQuery 解码 HTML 实体?
Javascript 中的 HtmlSpecialChars 等价物?

I need to convert with escaped htmlspecialchars to a valid HTML code, for example:

我需要使用转义的 htmlspecialchars 转换为有效的 HTML 代码,例如:

<p>Text here</p>

should be displayed in the browser like

应该在浏览器中显示

Text here

在这打字

What is the right way to do that?

这样做的正确方法是什么?

Thanks in advance, Ivan.

提前致谢,伊万。

采纳答案by Ivan Gromov

回答by Oliver Spryn

Try the PHP.JS function to perform this action. Their examples solve exactly the question you are asking:

尝试使用 PHP.JS 函数来执行此操作。他们的例子正好解决了你问的问题:

http://phpjs.org/functions/htmlspecialchars_decode:427

http://phpjs.org/functions/htmlspecialchars_decode:427