1、去除左空格: String.prototype.LTrim = function() { return this.replace(/(^/s*)/g, ""); // wipe-left } 2、去除右空格 String.prototype.RTrim = function() { return this.replace(/(/s*$)/g, ""); //wipe-right } 3、去除左右空格 String.prototype.Trim = function() { return this.replace(/(^/s*) |(/s*$)/g, ""); //wipe-left-right } 4、去除所有空格 String.prototype.TrimAll = function() { return this.replace(//s+/g,""); //wipe-all }