简易代码之家

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  157 Posts :: 2 Stories :: 57 Comments :: 0 Trackbacks
 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 on 2008-04-25 17:29 Jakin.zhou 阅读(578) 评论(1)  编辑  收藏

Feedback

# re: Js计算包含英文与汉字的字符串长度 2014-07-24 16:19 是倒萨的是倒萨倒萨的撒旦是倒萨倒萨
是倒萨倒萨的撒旦撒旦撒旦撒  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: