JS将unicode码转中文方法

Thea ·
更新时间:2024-09-21
· 744 次阅读

原理,将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"> 



方法 unicode码 unicode js

需要 登录 后方可回复, 如果你还没有账号请 注册新账号