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的字节长度

posted @ 2014-08-20 16:15  李亚杰  阅读(766)  评论(0)    收藏  举报