httpsss://js.do/powenko/04-string-length
<script> var c="" function stringBytes(c){ var n=c.length,s; var len=0; for(var i=0; i <n;i++){ s=c.charCodeAt(i); while( s > 0 ){ len++; s = s >> 8; } } return len; } var tx="測試中文12313"; console.log(stringBytes(tx)); </script> <!-- edit your html here -->
輸出:
13