求javacript 写的与vbscript中trim 功能一样的函数 String.prototype.trim = function() { return (this.replace(/^\s+|\s+$/g,""));}alert(" cloudchen ".trim().bold()) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function trim(str){ return str.replace(/^[\s]+|[\s]+$/,"");}document.write(trim(" fdsdfs dfsdfs ")); function trim(str){ var i; i=0; while (i<str.length && str.charAt(i)==' ') i++; str=str.substr(i); i=str.length-1; while (i>=0 && str.charAt(i)==' ') i--; str=str.substr(0,i+1); return str;} /************************************function: trim(strInput)purpose: 去除字符串的前后空格parameters : strInput: 字符串return value : 去除前后空格的字符串************************************/function trim(strInput){ strInput=new String(strInput) var iLoop=0; var iLoop2=-1; var strChr; if((strInput == null)||(strInput == "<NULL>")) return ""; if(strInput) { for(iLoop=0;iLoop<strInput.length-1;iLoop++) { strChr=strInput.charAt(iLoop); if(strChr!=' ') break; } for(iLoop2=strInput.length-1;iLoop2>=0;iLoop2--) { strChr=strInput.charAt(iLoop2); if(strChr!=' ') break; } } if(iLoop<=iLoop2) { return strInput.substring(iLoop,iLoop2+1); } else { return ""; }} function trim(Str){ Str=Str.replae(/^ /g,""); Str=Str.replae(/ $/g,""); return Str;} <script language="JavaScript">function killspace(x) {while((x.length>0) && (x.charAt(0)==" ")) x=x.substring(1,x.length);while(x.length>0 && (x.charAt(x.length-1)==" ")) x=x.substring(0,x.length-1);return x;} 最简单的办法……<script language=VBscript runat=Server>function vbTrim(str) vbTrim=trim(str)end function</script>然后Js可以直接调用 purexu(星星) 的发言调试成功了,而且比较直观 请教页面嵌套中的问题 高分求解决用js实现Excel转换成PDF的代码的问题! 【找错】图片向左循环滚动代码 div被遮盖问题 下拉框点击事件后把隐藏的多种框显示出来(包括不在同行的下拉框,文本框) 紧急求助! 简单的问题?解决了就给分啊 窗口关掉问题! javascript怎样操作session或cookie? javascript 按钮的前后置逻辑设计求解 写聊天室javascript的小问题 谁有不看的《javascript宝典》,卖给我吧。
return str.replace(/^[\s]+|[\s]+$/,"");
}
document.write(trim(" fdsdfs dfsdfs "));
{ var i;
i=0;
while (i<str.length && str.charAt(i)==' ')
i++;
str=str.substr(i);
i=str.length-1;
while (i>=0 && str.charAt(i)==' ')
i--;
str=str.substr(0,i+1);
return str;}
function: trim(strInput)
purpose: 去除字符串的前后空格
parameters : strInput: 字符串
return value : 去除前后空格的字符串
************************************/
function trim(strInput)
{
strInput=new String(strInput)
var iLoop=0;
var iLoop2=-1;
var strChr;
if((strInput == null)||(strInput == "<NULL>"))
return "";
if(strInput)
{
for(iLoop=0;iLoop<strInput.length-1;iLoop++)
{
strChr=strInput.charAt(iLoop);
if(strChr!=' ')
break;
}
for(iLoop2=strInput.length-1;iLoop2>=0;iLoop2--)
{
strChr=strInput.charAt(iLoop2);
if(strChr!=' ')
break;
}
}
if(iLoop<=iLoop2)
{
return strInput.substring(iLoop,iLoop2+1);
}
else
{
return "";
}
}
{
Str=Str.replae(/^ /g,"");
Str=Str.replae(/ $/g,"");
return Str;
}
function killspace(x) {
while((x.length>0) && (x.charAt(0)==" ")) x=x.substring(1,x.length);
while(x.length>0 && (x.charAt(x.length-1)==" ")) x=x.substring(0,x.length-1);
return x;
}
function vbTrim(str)
vbTrim=trim(str)
end function
</script>然后Js可以直接调用