js-统计中文,英文,字符的个数
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哈'));