<div class="codetitle"> <span><a style="CURSOR: pointer" data="96770" class="copybut" id="copybut96770" onclick="doCopy('code96770')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code96770"> <br><script type="text/javascript"> <BR>var zfl={}; <BR>zfl.GetLength = function(str){ <BR>var realLength = 0,len = str.length,charCode = -1; <BR>for(var i=0;i<len;i++){ <BR>charCode = str.charCodeAt(i); <BR>if(charCode>0 && charCode<=128) realLength +=1; <BR>else realLength += 2; <BR>else realLength += 2; <BR>else realLength += 2; <BR><script type="text/javascript"> <BR>alert(zfl.GetLength("中国123zkrljl")); <BR></script> <br> </div> <br>效果如图: <br><img src="http://files.jb51.net/file_images/article/201403/20140319115121.jpeg?2014219115144" alt="js判断字符长度及中英文数字等_javascript技巧" >