核心函数:
<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;
return realLength;
}
</script>
使用实例:
<script type="text/javascript">
alert(zfl.GetLength("中国123zkrljl"));
</script>
效果如图: