从网上 抄下 如下的代码:

//汉字转化成 实体
function ascii(str) {
return str.replace(/[^\u0000-\u00FF]/g, function($0) {
return escape($0).replace(/(%u)(\w{4})/gi, “\&#x$2;”)
});
}
// 汉字转化成 unicode
function unicode(str) {
return str.replace(/[^\u0000-\u00FF]/g, function($0) {
return escape($0).replace(/(%u)(\w{4})/gi, “\u$2”)
});
}
// unicode 转 汉字
function reconvert(str) {
str = str.replace(/(\u)(\w{4})/gi, function($0) {
return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{4})/g, “$2”)), 16)));
});
str = str.replace(/(&#x)(\w{4});/gi, function($0) {
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{4})(%3B)/g, “$2”), 16));
});
return str;
}