时间:2022-08-10 09:39:02 | 栏目:JavaScript代码 | 点击:次
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);