版权声明:本文为博主落尘曦的原创文章。如转载请注明链接 【 落尘曦的博客:http://blog.csdn.net/qq_23994787 】感谢配合! https://blog.csdn.net/qq_23994787/article/details/86609659
JS计算字符串字节长度
String.prototype.byteLength = function() {
var count = 0;
for(var i=0,l=this.length;i<l;i++) {
count += this.charCodeAt(i) <= 128 ? 1 : 2;
}
return count;
}