<script> <BR>function subString(str, len, hasDot) <BR>{ <BR>var newLength = 0; <BR>var newStr = ""; <BR>var chineseRegex = /[^\x00-\xff]/g; <BR>var singleChar = ""; <BR>var strLength = str.replace(chineseRegex,"**").length; <BR>for(var i = 0;i < strLength;i++){ <BR>singleChar = str.charAt(i).toString(); <BR>if(singleChar.match(chineseRegex) != null){ <BR>newLength += 2; <BR>}else{ <BR>newLength++; <BR>} <BR>if(newLength > len){ <BR>break; <BR>} <BR>newStr += singleChar; <BR>} <br><br>if(hasDot && strLength > len){ <BR>newStr += "..."; <BR>} <BR>return newStr; <BR>} <BR>alert(subString("js截取中英文字符串无乱码",10,true)); <BR></script>