原文:http://www.happyshow.org/content.asp?id=114

 

代码示例如下:

 1 <script language="javascript">
 2 String.prototype.trim=function(){
 3         return this.replace(/(^\s*)|(\s*$)/g, "");
 4 }
 5 String.prototype.ltrim=function(){
 6         return this.replace(/(^\s*)/g,"");
 7 }
 8 String.prototype.rtrim=function(){
 9         return this.replace(/(\s*$)/g,"");
10 }
11 
12 function test(){
13     var strWithSpace = '   12345   ';
14     window.alert(strWithSpace+"_"+strWithSpace.length);
15 
16     strWithSpace = strWithSpace.trim();
17     window.alert(strWithSpace+"_"+strWithSpace.length);
18 }
19 
20 window.onload = test ;
21 </script>

相关文章:

  • 2022-02-21
  • 2021-08-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2021-08-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-24
相关资源
相似解决方案