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 && c<=0xff9f)) {
8 totalCount++;
9 }else {
10 totalCount+=2;
11 }
12 }
13 // alert(totalCount);
14 return totalCount;
15}
16//-->
17</SCRIPT>
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 && c<=0xff9f)) {
8 totalCount++;
9 }else {
10 totalCount+=2;
11 }
12 }
13 // alert(totalCount);
14 return totalCount;
15}
16//-->
17</SCRIPT>