比较简单实用的使用正则三种版本的js去空格处理方法
发布时间:2016-12-30 来源:查字典编辑
摘要:分别去字符串前后,左边,右边空格复制代码代码如下:String.prototype.trim=function(){returnthis.r...
分别去字符串前后,左边,右边空格
复制代码 代码如下:
String.prototype.trim=function(){returnthis.replace(/^s+|s+$/g,"")}
String.prototype.ltrim=function(){returnthis.replace(/^s+/g,"")}
String.prototype.rtrim=function(){returnthis.replace(/s+$/g,"")}