String.prototype.trim= function(){ // 用正则表达式将前后空格 // 用空字符串替代。 return this.replace(/(^s*)|(s*$)/g, ""); }使用:var str=' 123 ';str.trim();//去左右两边的空格