对javascript中String类型的拓展
2018-07-20 来源:open-open
/**
*
* @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,'');
}
}
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:java 压缩解压文件
下一篇:JAVA的AES加密步骤解释
最新资讯
热门推荐