例如加trim()清除左右空格String.prototype.trim=function() { return this.replace(/(^\s*)|(\s*$)/g,''); }调用var str=" test "; str = str.trim();