String.prototype.byteLen = function(){
var len = 0,
i = this.length;
while(i--)
{
len += (this.charCodeAt(i)>255 ? 2 : 1);
}
return len;
}; ("测试").byteLen(); //会返回4 ("aaa").byteLen(); //会返回3
String.prototype.byteLen = function(){
var len = 0,
i = this.length;
while(i--)
{
len += (this.charCodeAt(i)>255 ? 2 : 1);
}
return len;
}; ("测试").byteLen(); //会返回4 ("aaa").byteLen(); //会返回3