function byteLength(str) { var byteLen = 0, len = str.length; if( !str ) return 0; for( var i=0; i<len; i++ ) byteLen += str.charCodeAt(i) > 255 ? 2 : 1; return byteLen; }
js计算字符串字节长度
最新推荐文章于 2024-04-08 18:22:08 发布
function byteLength(str) { var byteLen = 0, len = str.length; if( !str ) return 0; for( var i=0; i<len; i++ ) byteLen += str.charCodeAt(i) > 255 ? 2 : 1; return byteLen; }