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));
转载自:http://www.cnblogs.com/chu888chu888/archive/2012/02/15/2352169.html
转载于:https://www.cnblogs.com/hutaoer/archive/2012/11/21/3078880.html