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