js去空格技巧分别去字符串前后、左右空格_javascript技巧
                        
                            时间:2021-07-01 10:21:17
                            帮助过:7人阅读
							                        
                     
                    
                    分别去字符串前后,左边,右边空格 
 代码如下:
 
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,"")} 
String.prototype.ltrim = function(){ return this.replace(/^\s+/g,"")} 
String.prototype.rtrim = function(){ return this.replace(/\s+$/g,"")} 
 为String对象增加一个trim方法。 
以后就可以这样使用: 
 代码如下:
 
var s = " abc "; 
s = s.trim(); // s是个String,可以使用刚定义的trim方法。 
alert(s);