javascript 使用正则实现 trim方法

 1 String.prototype.Trim = function() 
 2 { 
 3 return this.replace(/(^\s*)|(\s*$)/g, ""); 
 4 } 
 5 String.prototype.LTrim = function() 
 6 { 
 7 return this.replace(/(^\s*)/g, ""); 
 8 } 
 9 String.prototype.RTrim = function() 
10 { 
11 return this.replace(/(\s*$)/g, ""); 
12 } 

 

posted on 2019-03-08 20:39  时光游弋  阅读(395)  评论(0编辑  收藏  举报