function getByteLen(val) { var len = 0; for (var i = 0; i < val.length; i++) { var a = val.charAt(i); if (a.match(/[^x00-xff]/ig) != null) { len += 1; } else { len += 0.5; } } return len; } alert(getByteLen('aa7,.o哈'));
function getByteLen(val) { var len = 0; for (var i = 0; i < val.length; i++) { var a = val.charAt(i); if (a.match(/[^x00-xff]/ig) != null) { len += 1; } else { len += 0.5; } } return len; } alert(getByteLen('aa7,.o哈'));