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>
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>
相关文章推荐
- js处理空格的函数
- js空格处理函数
- 一个js过滤空格的小函数
- JS 里面的 eval() 函数的作用和报错之后的处理
- 对于js中eval()函数的理解 和 写一个函数trim() 去掉字符串左右空格
- 详解js中常规日期格式处理、月历渲染和倒计时函数
- js常规日期格式处理、月历渲染、倒计时函数
- JS字符串处理函数
- JS 里面的 eval() 函数的作用和报错之后的处理
- JS中关于事件处理函数名后面是否带括号的问题
- js笔记十二:利用await和async,将回调函数变成同步的处理的办法
- JS--构建自己的函数库之——浏览器兼容问题处理(持续构建中……)
- js 处理数据里面的空格
- 在js的函数中用jquery的trim()方法去掉search前后的空格
- js去除空格函数
- JS数组(Array)处理函数总结
- js中URL中带有空格参数的处理方法
- JS日期(Date)处理函数总结
- js使用函数绑定技术改变事件处理程序的作用域
- JS判断字符串是否为空、过滤空格、查找字符串位置等函数集