一个汉字为2个字符,一个数字或字母为一个字符 function byteCount(str) { return str && str.replace(/[^\x00-\xff]/g,"xx").length || 0; }