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; 

posted on 2014-09-25 00:01  Young_Junior_Man  阅读(195)  评论(0编辑  收藏  举报

导航