<script> <BR>(function($){ <BR>$.extend($,{ <BR>fixedWidth:function(str,length,char){ <BR>str=str.toString(); <BR>if(!char) char="..."; <BR>var num=length-lengthB(str); <BR>if(num<0){ <BR>str=substringB(str,length-lengthB(char))+char; <BR>} <BR>return str; <BR>function substringB(str,length){ <BR>var num=0,len=str.length,tenp=""; <BR>if(len){ <BR>for(var i=0;i<len;i++){ <BR>if(num>length) break; <BR>if(str.charCodeAt(i)>255){ <BR>num+=2; <BR>tenp+=str.charAt(i); <BR>}else{ <BR>num++; <BR>tenp+=str.charAt(i); <BR>} <BR>} <BR>return tenp; <BR>}else{ <BR>return null; <BR>} <BR>} <BR>function lengthB(str){ <BR>var num=0,len=str.length; <BR>if(len){ <BR>for(var i=0;i<len;i++){ <BR>if(str.charCodeAt(i)>255){ <BR>num+=2; <BR>}else{ <BR>num++; <BR>} <BR>} <BR>return num; <BR>}else{ <BR>return 0; <BR>} <BR>} <BR>} <BR>}); <BR>})(jQuery); <BR>var a="abcde我是谁呢?"; <BR>alert(jQuery.fixedWidth(a,10)); <BR></script>