晕。javascript没有trim函数?

WorldCreater 2004-09-22 04:41:30
晕。javascript没有trim函数?
好久没写这东西了,忘得厉害

<form id="scanInputForm" action="" method="post" onsubmit=''>
请输入:<input type="text" name="nsrsbh" value="35010219771124089601">
<button name="showAttachmentBtn" onclick='if(document.all.scanInputForm.nsrsbh.value==""){alert("请输入");exit();}
//////////////这里加上trim的话就没反应 trim(document.all.scanInputForm.nsrsbh.value)==""

document.all.scanInputForm.action="showallfjbynsrsbh.jsp";document.all.scanInputForm.submit()'>查看附件</button>
<button name="showScannerFormBtn" onclick='if(document.all.scanInputForm.nsrsbh.value==""){alert("请输入");exit();}document.all.scanInputForm.action="scanner.jsp";document.all.scanInputForm.submit()'>扫描输入</button>
</form>
...全文
405 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
AspNet2005 2005-08-07
  • 打赏
  • 举报
回复
String.prototype.trim() = function()
{
return this.replace(/(^\s*)|(\s*$)/g);
}
WorldCreater 2004-09-23
  • 打赏
  • 举报
回复
trim函数还要自个写?
  • 打赏
  • 举报
回复
whnnet(赚钱攒嫁妆)MM写的非常好…………
张佩 2004-09-22
  • 打赏
  • 举报
回复
ding
wenww 2004-09-22
  • 打赏
  • 举报
回复
function trim(strValue)
{
if(strValue==null || strValue.length == 0) return ("");
var cr=String.fromCharCode(13);
var oldstr="";

while (oldstr.length!=strValue.length)
{
oldstr = strValue;
strValue=b_trim(strValue," ");
strValue=b_trim(strValue," ");
strValue=b_trim(strValue,cr);
}
return strValue;
}
JasonJHu 2004-09-22
  • 打赏
  • 举报
回复
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, "");
}
whnnet 2004-09-22
  • 打赏
  • 举报
回复

// 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, "");
}


使用:

x = " d "
alert(x.Trim())

87,904

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧