function testc(str) {
//默认为0
var count = 0;
for(var i = 0; i < str.length; i++) {
//循环获取每一个字符
var c = str.charAt(i);
//console.log(c);
//正则,匹配中文, count + 2; 否则 + 1
if(/[^\u0000-\u00ff]/.test(c)) {
count += 2;
//console.log(count);
} else {
count += 1;
}
}
console.log(count);
}
//调用
var jj = "一而点的wdd我w";
testc(jj);