猿问
js如何判断 有中文的字符串的长度?
js如何判断 有中文的字符串的长度
手掌心
浏览 523
回答 1
1回答
30秒到达战场
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
0
0
随时随地看视频
慕课网APP
相关分类
JavaScript
我要回答