js如何判断 有中文的字符串的长度
1 回答

30秒到达战场
TA贡献1828条经验 获得超6个赞
String.prototype.gblen = function() {
var len = 0;
for (var i=0; i<this.length; i++) {
if (this.charCodeAt(i)>127 || this.charCodeAt(i)==94) {
len += 2;
} else {
len ++;
}
}
return len;
}
添加回答
举报
0/150
提交
取消