1. 去掉字符串两端的空格
String.prototype.trim=function (){return this.replace(/(^/s*)|(/s*$)/g,'');}
2. 去掉字符串中所有的空格:
String.prototype.sTrim = function (){return this.replace(//s/g, '');}
或者:
var s = "asd ddd bbb sss";
var reg = //s/g;
var ss = s.replace(reg, "");
alert(ss);