這篇文章主要介紹了js判斷字符長度及中英文數字等,需要的朋友可以參考下
代碼如下: <script type="text/javascript"> var zfl={}; zfl.GetLength = function(str){ var realLength = 0,len = str.length,charCode = -1; for(var i=0;i<len;i++){ charCode = str.charCodeAt(i); if(charCode>0 && charCode<=128) realLength +=1; else realLength += 2; else realLength += 2; else realLength += 2; <script type="text/javascript"> alert(zfl.GetLength("中國123zkrljl")); </script>