<script type= "text/javascript" > var GB2312UnicodeConverter = { ToUnicode: function (str) { return escape(str).toLocaleLowerCase().replace(/%u/gi, '\\u' ); } , ToGB2312: function (str) { return unescape(str.replace(/\\u/gi, '%u' )); } }; var str = '上海' , unicode; document.write(str + '<br/>' ); unicode = GB2312UnicodeConverter.ToUnicode(str); document.write( '汉字转换为Unicode代码:' + unicode + '<br/><br/>' ); document.write( 'Unicode代码转换为汉字:' + GB2312UnicodeConverter.ToGB2312(unicode)); </script> |
来源:https://www.cnblogs.com/qqyuhaitao/p/4228760.html