//截取字符串(包含中文处理) str 要截取的字符串 len 截取长度 hasfix 是否加...后缀
function subString(str, len, hasfix){
var newLength = 0;
var newStr = "";
var chineseRegex = /[^/x00-/xff]/g;
var singleChar = "";
var strLength = str.replace(chineseRegex,"**").length;
for(var i = 0;i < strLength;i++){
singleChar = str.charAt(i).toString();
if(singleChar.match(chineseRegex) != null){
newLength += 2;
}else{
newLength++;
}
if(newLength > len){
break;
}
newStr += singleChar;
}
if(hasfix && strLength > len){
newStr += "...";
}
return newStr;
}