JS 去空格函数
2007-10-18 13:43
197 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
function jtrim(s)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
var i,b=0,e=s.length;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(i=0;i<s.length;i++) //去左空格
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(s.charAt(i)!=' ')...{b=i;break;}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if(i==s.length)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return "";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(i=s.length-1;i>b;i--) 去右空格
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
if(s.charAt(i)!=' ')...{e=i;break;}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return s.substring(b,e+1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
下面的更好点
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//去左空格;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function ltrim(s)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return s.replace( /^s*/, "");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//去右空格;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function rtrim(s)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return s.replace( /s*$/, "");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//去左右空格;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
function trim(s)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return rtrim(ltrim(s));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
相关文章推荐
- 在动态THML语句中调用JS函数传递带空格参数的问题
- js 去除左右空格 最精炼的函数
- 对于js中eval()函数的理解 和 写一个函数trim() 去掉字符串左右空格
- JS 常用函数 去空格、去重复元素 jquery去空格 1410231
- js中eval()函数和trim()去掉字符串左右空格应用
- JS 常用函数(去空格、去重复元素)
- IE8 js trim函数 去空格函数与正则集锦
- 一个js过滤空格的小函数
- js去除字符串空格函数
- JS判断字符串是否为空、过滤空格、查找字符串位置等函数集
- 在js的函数中用jquery的trim()方法去掉search前后的空格
- JS函数.去掉字符串前后两端空格
- js处理空格的函数
- js去除空格函数
- js去空格函数(方法)
- js去空格函数(方法)
- js中eval()函数和trim()去掉字符串左右空格应用
- 对于js中eval()函数的理解 和 写一个函数trim() 去掉字符串左右空格
- js trim函数去空格函数与正则集锦
- js空格处理函数