方法一:
str.replace(/[^\x00-\xff]/g, 'xx').length
方法二:
String.prototype.byteLen = function(){
var len = 0,
i = this.length;
while(i--)
{
len += (this.charCodeAt(i)>255 ? 2 : 1);
}
return len;
}
调用:str.byteLen ()