日期:2014-05-16 浏览次数:20403 次
function countCharacters(str){
???? var totalCount = 0;
??? ?
???? for (var i=0; i<str.length; i++) {
???????? var c = str.charCodeAt(i);
???????? if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {
???????????? totalCount++;
???????? }else {?? ?
???????????? totalCount+=2;
???????? }
??????? ?
???? }
???? return totalCount;
?? ?
}