js获取中文/中英文/英文的字节长度
1 String.prototype.getBytes = function() { 2 var cArr = this.match(/[^\x00-\xff]/ig); 3 return this.length + (cArr == null ? 0 : cArr.length); 4 }
使用:
var a = "我就是我sdf";
alert(a.getBytes());//这就是a的字节长度
1 String.prototype.getBytes = function() { 2 var cArr = this.match(/[^\x00-\xff]/ig); 3 return this.length + (cArr == null ? 0 : cArr.length); 4 }
使用:
var a = "我就是我sdf";
alert(a.getBytes());//这就是a的字节长度