String.prototype.trim = function(){ return this.replace(/(^s*)|(s*$)/g, ""); } 转载于:https://www.cnblogs.com/momomo/archive/2011/07/13/2105568.html