如何使用jQuery解码HTML实体? [英] How to decode HTML entities using jQuery?

查看:148
本文介绍了如何使用jQuery解码HTML实体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用jQuery解码字符串中的HTML实体?

How do I use jQuery to decode HTML entities in a string?

推荐答案


安全注意事项:使用此答案(以其原始格式保存)可能会引入 XSS漏洞到您的应用程序中。 您不应该使用此答案。请阅读 lucascaro的回答,以获得对此答案中漏洞的解释,并使用该答案或 Mark Amery的答案代替。

Security note: using this answer (preserved in its original form below) may introduce an XSS vulnerability into your application. You should not use this answer. Read lucascaro's answer for an explanation of the vulnerabilities in this answer, and use the approach from either that answer or Mark Amery's answer instead.

实际上,请尝试

Actually, try

var decoded = $("<div/>").html(encodedStr).text();

这篇关于如何使用jQuery解码HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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