/** * 去空格 */ 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,""); };
原文:http://www.cnblogs.com/rainheader/p/4595309.html