关于ASP中的客户端VBSCRIPT问题

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:52:38
<body>

<form id="form1" name="form1" method="POST" action="login.asp?p=t" onsubmit="return Chkfields();">
<table width="265" border="0" align="center">
<tr>
<td colspan="2" bgcolor="#66CCFF"><div align="center" class="STYLE1">管理员登录</div></td>
</tr>
<tr>
<td>用户名:</td>
<td><label>
<input type="text" name="txtName" />
</label></td>
</tr>
<tr>
<td>密码:</td>
<td><label>
<input type="password" name="txtPwd" />
</label></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<label>
<input type="subm

如果onsubmit="return Chkfields()"要去掉return那需要改变Chkfields()函数了如下:
<script language=vbscript>
function Chkfields()
if form1.txtName.value="" then
window.alert("请输入用户名!")
return false
exit function
End if
if form1.txtPwd.value="" then
window.alert("请输入密码!")
return false
exit function
End if
return true
end function
</script>

第一个问题:
onsubmit="return Chkfields();"关键在这里面的分号,语句后面加分号是JS的写法,把它去掉onsubmit="return Chkfields()"就没问题了。至于为什么放后面就可以,有点费解,我也想不明白。
第二个问题:
return的意思是把 Chkfields()执行后的结果返回给onsubmit,也就是Chkfields = false 或者Chkfields = true ,只有onsubmit接收到的是true,action才会被执行。如果没有return,它的意思就是执行Chkfields()这个函数,但这个函数永远为真,所以如果没有return,不管验证通没通过,action都会被执行。