废话不说了,直接上代码


//unicode转换
$.extend({
 //unicode编码,例:$.enUnicode("中文,eng")
//结果:"\u4e2d\u6587,eng"
 enUnicode: function (v) {
 var ascii = "";
 for (var i = 0; i < v.length; i++) {
 var code = Number(v[i].charCodeAt(0));
 if (code > 127) {
 var charAscii = code.toString(16);
 charAscii = new String("0000").substring(charAscii.length, 4) + charAscii;
 ascii += "\\u" + charAscii;
 } else {
 ascii += v[i];
 }
 }
 return ascii;
 },
 //unicode解码,例:$.deUnicode("\u4e2d\u6587,eng")
//结果:"中文,eng"
 deUnicode: function (v) {
 var r = v.match(/\\u[0-9a-fA-F]{4}/g);
 if (r == null) {
 return v;
 }
 for (var i = 0; i < r.length; i++) {
 v = v.replace(r[i], unescape(r[i].replace("\\u", "%u")));
 }
 return v;
 }
});