function String.prototype.trim(){
 return  this.replace(/(^\s*)|(\s*$)/g, "");
}
alert(">>"+"  abcd    ".trim()+"<<")

解决方案 »

  1.   

    <script language="Javascript"><!--
    //JS里没有,我们自己定义:
    String.prototype.Trim  = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
    String.prototype.LTrim = function(){return this.replace(/(^\s*)/g, "");}
    String.prototype.Rtrim = function(){return this.replace(/(\s*$)/g, "");}
    var str = "   abcdefg   "
    alert(str+":"+str.Trim());
    // --></script>
      

  2.   

    function String.prototype.trim()
     {
     return  this.replace(/(^\s*)|(\s*$)/g, "");
     }
    alert(">>"+"  abcd    ".trim()+"<<")
      

  3.   

    只能自己写个:
    function trim(value){
    var res = String(value).replace(/^[\s]+|[\s]+$/g,'');
    return res;
    }
      

  4.   

    问过无数遍了。FAQ里没有么?