String.prototype.trim1=function(){
    return this.replace(/(^\s*)|(\s*$)/g,"");
  };

 

 

写一个function,清除字符串前后的空格(兼容所有的浏览器)

 

  function trim1(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }