简体   繁体   中英

How to render unicode escape sequences using javascript?

Below code,

document.writeln("Caracteres escapados {\u55e8\uff0c\u4f60\u597d\u5417}: "
                                                    + "\u55e8\uff0c\u4f60\u597d\u5417");

expected output is \嗨\,\你\好\吗: 嗨,你好吗

Current output is: Caracteres escapados {嗨,你好吗}: 嗨,你好吗

What modification is required in the above code?

只需不翻译就跳过要显示的代码的反斜杠即可:

 document.writeln("Carácteres escapados \\\嗨\\\,\\\你\\\好\\\吗: \嗨\,\你\好\吗"); 

You need to escape your backslashes and remove the braces.

document.writeln("Caracteres escapados \\u55e8\\uff0c\\u4f60\\u597d\\u5417 "
                                                    + "\u55e8\uff0c\u4f60\u597d\u5417");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM