<html> <head> <meta charset="UTF-8"/> <title>截取字串长度</title> </head> <body> <script type="text/javascript"> function cutStr(str,len){ var temp=''; var icount=0; var pattn=/[^x00-xff]/; var strre=''; for(var i=0;i<str.length;i++){ if(icount<len-1){ temp=str.substr(i,1); if(pattn.exec(temp)==null){ icount++; }else{ icount+=2; } strre+=temp; }else{ break; } } return strre+'...'; } var str="菜鸟出没jdsdsdsdderer"; var result=cutStr(str, 5) ; document.write(result); </script> </body> </html>