对string的属性扩展String.prototype.trimall = function(){ return this.replace(/\s+/g, ""); }String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/, "");}String.prototype.triml = function(){ return this.replace(/(^\s*)/, "");}String.prototype.trimr = function(){ return this.replace(/(\s*$)/, "");}
如何用以上的方法var str = " abc def ";str.trimall();