JavaScript去除字符串左右的空格 //去掉左右空格 function String.prototype.Trim() { return this.replace(/(^\s*)|(\s*$)/g, ""); } //调用的时 str.Trim()就好了