原理,将unicode的 u 先转为 %u,然后使用unescape方法转换为中文。
1
2
3
4
|
<script type= "text/javascript" > var str = "u7434u5fc3u5251u9b44u4ecau4f55u5728uff0cu6c38u591cu521du6657u51ddu78a7u5929u3002" ; document.write(unescape(str.replace(/\u/g, '%u' ))); //琴心剑魄今何在,永夜初晗凝碧天。 </script> |
记得head标记中加入
<meta http-equiv="content-type" content="text/html; charset=utf-8">