<script> <BR>function subString(, lention , hasDot) <BR>{ <BR>var newLength = 0; <BR>var newStr = ""; <BR>var chineseRegex = /[^x00-xff]/g; <BR>var singleCharex = ""; 🎜>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>return newStr; <BR>} <BR>alert(subString("js截取中英文字串無亂碼",10,true)); <BR></script>