javascript没有这个功能的
要自己写一个函数的

解决方案 »

  1.   

    function ReplaceDemo(){
       var r, re;                    // 声明变量。
       var ss = "The man hit the ball with the bat.\n";
       ss += "while the fielder caught the ball with the glove.";
       re = /\s/g;             // 创建正则表达式模式。
       r = ss.replace(re, "");    // 用 "" 替换 空字符。
       return(r);                   // 返回替换后的字符串。
    }
      

  2.   

    String.prototype.trim = function() {
    return (this.replace(/^\s+|\s+$/g,""));
    }
    alert("    cloudchen    ".trim().bold())