给js的String添加trim方法

  1. String.prototype.trim = function() {     
  2.     //return this.replace(/[(^\s+)(\s+$)]/g,"");//會把字符串中間的空白符也去掉     
  3.     //return this.replace(/^\s+|\s+$/g,""); //     
  4.     return this.replace(/^\s+/g,"").replace(/\s+$/g,"");     
  5. }  

 

posted on 2011-03-01 16:45  %小Y%  阅读(248)  评论(3)    收藏  举报