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;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript