js去除空格

1       String.prototype.trim=function(){
2       return this.replace(/(^\s*)|(\s*$)/g, "");
3    }
4    String.prototype.ltrim=function(){
5       return this.replace(/(^\s*)/g,"");
6    }
7    String.prototype.rtrim=function(){
8       return this.replace(/(\s*$)/g,"");
9    }

 

1    function trim(str){ //删除左右两端的空格
2        return str.replace(/(^\s*)|(\s*$)/g, "");
3    }
4    function ltrim(str){ //删除左边的空格
5        return str.replace(/(^\s*)/g,"");
6    }
7    function rtrim(str){ //删除右边的空格
8        return str.replace(/(\s*$)/g,"");
9    }

 

posted @ 2016-08-02 18:03  wujinfeng  阅读(108)  评论(0)    收藏  举报