就像VBS里的trim一样。

解决方案 »

  1.   

    String.prototype.trim = function()
    {
        return this.replace(/(^[\\s]*)|([\\s]*$)/g, "");
    }就这么简单
      

  2.   

    去除空格3种方法 如下://去除字符串中间空格
    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, ""); 
    }如还不懂 继续跟帖!
      

  3.   

    调用方法就是:
    var str = "   12345   ";
    alert(str.Trim());
    alert(str.LTrim());
    alert(str.RTrim())
      

  4.   

    javascript 本身的身体日过你类型就有trim方法的啊
      

  5.   

    String.prototype.trim = function() 

        return this.replace(/(^[\\s]*)|([\\s]*$)/g, ""); 
    }
    var s = "    This is a String        ";
    s = s.trim(); // s = "This is a String"
      

  6.   

    晕..用trim啊 为什么不用呢>.<
      

  7.   

    var sB=" 1 23 ";
    var sA=sB.replace(/(^\s*)|(\s*$)/g,"");
    去掉前后空格