Core function:
Copy code code as follows:
<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>
Use examples:
Copy code code as follows:
<script type = "text/javascript">
Alert (zfl.getlength ("China 123ZKRLJL");
</script>
The effect is shown in the figure: