如何通过JavaScript解码unicode HTML? [英] How to decode unicode HTML by JavaScript?

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

问题描述

如何使用JavaScript解码:

How to use JavaScript to decode from:

\u003cb\u003estring\u003c/b\u003e

<b>string</b>

(我在互联网上搜索,有一些网站有同样的问题,例如:
Javascript html解码


如何解码HTML实体

没有相同的编码格式

非常感谢!

(I searched in internet, there are some site with same question, such as: Javascript html decoding
or How to decode HTML entities
but it dont have same encode fomat)
Thank you very much!

推荐答案

decodeURIComponent('\u003cb\u003estring\u003c/b\u003e');

//  "<b>string</b>"

编辑 - 如果可以,我会删除上述答案。

Edit - I would delete the above answer if I could.

原始问题有点含糊不清。

The original question is a bit ambiguous.

console.log('\ u003cb \ u003estring \ u003c / b\\\>'); 已经产生< b>字符串< / b>

如果 \ 字符被转义,则可以使用替换方法替换 \\ 只需 \ ,从而允许正确的Unicode转义序列。

If the \ characters are escaped, then a replacement method could be used to replace \\ with just \, thus allowing the proper Unicode escape sequence.

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

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