js判断字符长度 //中文占用两个字符,英文占用一个字符String.prototype.gblen = function() { var len = 0; for (var i=0; i 127 || this.charCodeAt(i)==94) { len += 2; } else { len ++; } } return len; };var str = "我的ad_d
//中文占用两个字符,英文占用一个字符 String.prototype.gblen = function() { var len = 0; for (var i=0; i127 || this.charCodeAt(i)==94) { len += 2; } else { len ++; } } return len; }; var str = "我的ad_ds.,/o他"; var str_1 = "das=+..,"; console.log(str.gblen()); //打印结果为15, console.log(str_1.gblen()); //打印结果为8