小白的博客

this my!
javascrpt 去掉空格

//去左空格;
function ltrim(s)
{
    
return s.replace(/(^\s*)/g, "");
}

//去右空格;
function rtrim(s)
{
    
return s.replace(/(\s*$)/g, "");
}

//去左右空格;
function trim(s)
{
    
//return s.replace(/(^\s*)|(\s*$)/g, "");
    return rtrim(ltrim(s));
}

      

原型方法:
<SCRIPT LANGUAGE="JavaScript">
<!--
//出处:网上搜集
Trim()
Ltrim()
RTrim()
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, "");
}

//-->
</SCRIPT>

posted on 2008-07-11 12:14  baifan  阅读(353)  评论(1编辑  收藏  举报

Dilectio Theme is created by: Design Disease brought to you by Smashing Magazine