您的位置:首页 > Web前端 > JavaScript

js空格处理函数

2008-11-28 18:03 253 查看
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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: