当前位置: 代码迷 >> JavaScript >> js去掉上下空格
  详细解决方案

js去掉上下空格

热度:420   发布时间:2012-10-30 16:13:36.0
js去掉左右空格
引入文件夹js下面stringfunctions.txt这一个js文件

<SCRIPT src="${pageContext.request.contextPath}/js/stringfunctions.txt" type=text/javascript></SCRIPT>


var projectId = fnsTrim(" test String  " );

js去掉左右空格
function fnsTrim(Instring)
{

OutString=""
Instring = new String(Instring)
OutString=fnsRtrim(fnsLtrim(Instring))
return(OutString);

}

js去掉右边空格
function fnsRtrim(Instring)
{
OutString=""
Instring = new String(Instring)
for(count=Instring.length;count >0;count--)
{

tempchar=Instring.substring(count,count-1)
if (tempchar != " ")
break;
}

OutString=Instring.substring(0,count);
return(OutString);

}


fs去掉左边空格
function fnsLtrim(Instring)
{
OutString=""
Instring = new String(Instring)
for(count=0;count < Instring.length;count++)
{

tempchar=Instring.substring(count,count+1)
if (tempchar != " ")
break;
}

OutString=Instring.substring(count,Instring.length);
return(OutString);

}
  相关解决方案