标签:htm ref logs length lan escape div ret 编码
//UTF字符转换
var UTFTranslate = {
Change:function(pValue){
return pValue.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
},
ReChange:function(pValue){
return unescape(pValue.replace(/&#x/g,‘%u‘).replace(/\\u/g,‘%u‘).replace(/;/g,‘‘));
}
};
例如:
UTFTranslate.ReChange(‘中文sdfdf‘); //"中文sdfdf"
UTFTranslate.Change(‘中文sdfsf‘); // "中文sdfsf"
//Asc转换
var AscTranslate = {
Change: function(pAscString, pBoxId){
/* 转ASCII */
box = document.getElementById(pBoxId);
box.innerHTML = ‘‘;
for(i = 0; i < pAscString.length; i++)
{
var asc = pAscString.charCodeAt(i);
var str = String.fromCharCode(asc);
box.innerHTML += str + ‘:‘ + asc + ‘<br/>‘;
}
}
}
转自:http://www.cnblogs.com/if404/archive/2012/05/13/2498111.html
标签:htm ref logs length lan escape div ret 编码
原文地址:http://www.cnblogs.com/iwang5566/p/6798799.html