JS将unicode码转中文方法

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

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, '%u'))); //琴心剑魄今何在,永夜初晗凝碧天。</script>

记得head标记中加入

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


           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/hsyyff/article/details/83856645