关于表单检测是否为空的问题

linpast 2003-08-30 05:00:55
表单部分代码:

<form method="post" action="savedata.asp" name="guestbook" onsubmit="return check(this)">
<div align="center">
<center>
<table width="556" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="right" height="20">
<!-- #include file="bar.asp" -->
</td>
</tr>
</table>
<table border="0" cellspacing="0" width="522" cellpadding="0" height="364">
<tr>
<td height="20" bgcolor="<%=bgcolor1%>" style="border-top:<%=tablecolor%> 1px solid;border-left:<%=tablecolor%> 1px solid;border-right:<%=tablecolor%> 1px solid;">
<div align="center"><center>
<p><strong><font color="#0099CC">请 您 留 言</font></strong>
</center></div></td>
</tr>
<tr align="center">
<td height="329" valign="top" align="middle">
<div align="center"><center>
<table
border="0" cellpadding="0" width="522" height="310" cellspacing="0">
<tr>
<td width="94" height="25" class="td1">
<div align="right"> <font color="#0080C0" size="2">名 字:</font>
</div>
</td>
<td width="414" height="25" class="td6"><font>  </font>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td><font>
<input class="smallInput" name="name" size="20">
</font></td>
</tr>
</table></form>


检测表单是否为空代码:

<script language=javascript>
function check(theform)
{ var mystr1,mystr2,mylen,qqnum,qqlen,qqs;
mystr1=this.guestbook.email.value;
mylen=mystr1.length-5;
mystr2=mystr1.substring(1,mylen);
resultmy=mystr2.match("@");
qqnum=this.guestbook.qq.value
qqlen=qqnum.length
for(i=0;i<=qqlen;i++)
{qqs=qqnum.charAt(i)
if(qqs>=0 && qqs<=9)
{}
else
{alert('错误的QQ号码');
this.guestbook.qq.focus();
this.guestbook.qq.select();
return (false);
break;
}
}

if (this.guestbook.name.value=="")
{alert('请写上你的名字');
this.guestbook.name.focus();
return (false);
}
if (this.guestbook.email.value!="")
{
if (resultmy!="@")
{alert('请正确填写你的email地址');
this.guestbook.email.focus();
this.guestbook.email.select();
return (false);
}
}
for(i=0;i<=qqlen;i++)
{qqs=qqnum.charAt(i)
if(qqs>=0 && qqs<=9)
{}
else
{alert('错误的QQ号码');
this.user.qq.focus();
this.user.qq.select();
return (false);
break;
}
}
if (this.guestbook.title.value=="")
{alert('请写上主题');
this.guestbook.title.focus();
this.guestbook.title.select();
return (false);
}

}
</script>


在这边我有几个疑问:
一,在表单ACTION后面on submint跟的是return check(this), 可下面检测的代码又没有定义this这个参数?
二,检测的代码定义检测的表单为the from 又不是表单上面所定义的表单名guestbook?
这是为什么呢??
帮我分析一下谢谢.




...全文
92 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Iloveamao 2003-08-30
  • 打赏
  • 举报
回复
努力呀!
ceocio 2003-08-30
  • 打赏
  • 举报
回复
see:
http://www.csdn.net/develop/read_article.asp?id=17291
zhxhjj 2003-08-30
  • 打赏
  • 举报
回复
this代表当前对象
stefli 2003-08-30
  • 打赏
  • 举报
回复
你实在是不喜欢this的话,你就用全名称了.
document.guestbook.smallInput.value等等.
Brookes 2003-08-30
  • 打赏
  • 举报
回复
1.this在这里代表form
2.theForm就是这个表单呀!

//难道一点程序的概念都没有?努力呀!

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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