如何通过JavaScript解码unicode HTML? [英] How to decode unicode HTML by JavaScript?
问题描述
如何使用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屋!