mbStringLength 获取javascript字符串字节数

function mbStringLength(s) { 
var totalLength = 0; 
var i; 
var charCode; 
for (i = 0; i < s.length; i++) { 
charCode = s.charCodeAt(i); 
if (charCode < 0x007f) { 
totalLength = totalLength + 1; 
} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) { 
totalLength += 2; 
} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) { 
totalLength += 3; 


//alert(totalLength); 
return totalLength; 

原文地址:https://www.cnblogs.com/okBabyfaceBoy/p/3991834.html