encodeUnicode
作者:互联网
function encodeUnicodes(str) {
if (str == '')
return '';
var res ='';
for ( var i=0; i<str.length; i++ ) {
var s=str.charCodeAt(i).toString(16).slice(-4);
if (s.length==2)
{
res=res+str[i];
}
else
{
res=res+ "\\\\u"+ str.charCodeAt(i).toString(16) ;
}
}
return res;
}
标签:return,str,16,res,encodeUnicode,charCodeAt,var 来源: https://blog.csdn.net/ozhy111/article/details/95333691