コードコピーは次のとおりです。
<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>
効果は写真に示されています: