/**
*
* @desccrition: 对String类型去除空格的拓展
* @dir : 被去除空格所在的位置
* @test: ie6-9 chrome firefox
*/
String.prototype.trim = function(dir){
switch (dir) {
case 0 : //去左边的空格
return this.replace(/(^/s*)/g,'');
break;
case 1 : //去右边的空格
return this.replace(/(/s*$)/g,'');
break;
case 2 : //去掉所有的空格
return this.replace(/(/s*)/g,'');
break;
default : //去掉两边的空格
return this.replace(/(^/s*)|(/s*$)/g,'');
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/10025.html