1
2
3
4
5
6
7
8
9
10
11
12
function getByteLen(val) {
var len = 0;
for (var i = 0; i < val.length; i++) {
var code = val.charCodeAt(i);
if (code >= 0 && code <= 128) {
len += 1;
} else {
len += 2;
}
}
return len;
}
Post
Cancel
JQuery获取字符串字节长度
This post is licensed under
CC BY 4.0
by the author.