Home > php教程 > php手册 > javascript trim方法

javascript trim方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:01:17
Original
1275 people have browsed it

在javascript中的string对象没有trim方法,所以trim功能需要自己实现: 代码如下: scriptlanguage="javascript" /** *删除左右两端的空格 */ String.prototype.trim=function(){ return this.replace(/(^/s*)|(/s*$)/g, ''); } /** *删除左边的空格 */ Stri

 

在javascript中的string对象没有trim方法,所以trim功能需要自己实现: 

代码如下: 

 

/**

*删除左右两端的空格

*/  

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,'');  

}  

 

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template