Home > Web Front-end > JS Tutorial > Example code for converting unicode code into Chinese using JS

Example code for converting unicode code into Chinese using JS

零下一度
Release: 2017-05-10 11:06:58
Original
1941 people have browsed it

本篇文章主要介绍了JS将unicode码转中文方法的相关知识,具有很好的参考价值。下面跟着小编一起来看下吧

原理,将unicode的 \u 先转为 %u,然后使用unescape方法转换为中文。

<script type="text/javascript"> 
 var str = "\u7434\u5fc3\u5251\u9b44\u4eca\u4f55\u5728\uff0c\u6c38\u591c\u521d\u6657\u51dd\u78a7\u5929\u3002"; 
 document.write(unescape(str.replace(/\\u/g, &#39;%u&#39;))); //琴心剑魄今何在,永夜初晗凝碧天。 
</script>
Copy after login

记得head标记中加入

<meta http-equiv="content-type" content="text/html; charset=utf-8">
Copy after login

【相关推荐】

1. 免费js在线视频教程

2. JavaScript中文参考手册

3. php.cn独孤九贱(3)-JavaScript视频教程

The above is the detailed content of Example code for converting unicode code into Chinese using JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template