为什么点击了ALERT的确定键也能提交?

来源:百度知道 编辑:UC知道 时间:2024/06/10 04:24:46
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=GE-2312">
<link rel="stylesheet" type="text/css" href="../aspbook.css">
<title>注册新用户-步骤1</title>
</HEAD>
<script language="vbscript">
function mainform_onsubmit
if document.mainform.username.value="" then
alert "请输入您的名称!!"
return false
elseif len(document.mainform.username.value)<3 then
alert "您的名称至少需要三个字符!!"
return false
elseif document.mainform.password1.value<>document.mainform.password2.value then
alert "您输入的密码不匹配!!"
return false
elseif len(document.mainform.password1.value)<6 then
alert "您输入的密码至少需要六位!!"
return false
end if
return true
end function

</scr

给<form>加属性onsubmit="return:mainform_onsubmit()"

因为你的js很不规范。注意各组判断语句间要用{}括起来。否则,无论多少个判断,都只当一个语句块一起执行了。