Js计算包含英文与汉字的字符串长度

 1<SCRIPT language="JavaScript">
 2<!--
 3function countCharacters(str){
 4    var totalCount = 0;  
 5    for (var i=0; i<str.length; i++{  
 6        var c = str.charCodeAt(i);  
 7        if ((c >= 0x0001 && c <= 0x007e|| (0xff60<=&& c<=0xff9f)) {  
 8            totalCount++;  
 9        }
else {     
10            totalCount+=2;  
11        }
  
12    }

13    // alert(totalCount);
14    return totalCount;
15}

16//-->
17</SCRIPT>

 

posted @ 2008-04-25 17:29  Jakin.zhou  阅读(328)  评论(0编辑  收藏  举报