这段javascript代码不知道哪出错了,请指正

来源:百度知道 编辑:UC知道 时间:2024/06/30 17:18:54
这段代码是实现表单验证的一些功能,我不知道unsubmit的值该设成form1还是form2,另外用户名不能为空的提示已经实现,就是密码比较是否一致的代码还有错误。代码如下:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function checkform1()
{
if(document.my1.a1.value.length==0)
{
alert("用户名不能为空!");
document.my1.a1.focus();
return false;
}
return true;

}
function checkform2()
{
if(document.my1.PWD.value!=document.my1.PWD_again.value)
{
alert("你两次输入的密码不一样,请重新输入!")
document.ADDUser.PWD.focus();
return false;
}
return true;
}
</script>
</head>

<body>
<form name="my1" id="my1" action="" onsubmit="return checkform1()">
用户名<input type="text" name="a1"><br />

我帮你改了一下,你里边得项目名对不上所以报错
还有就是onsubmit好像不能同时调2个函数
不过你可以将这2个函数的内容合成为一个函数
如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>www</title>
<script>

function checkform2()
{
if(document.my1.a1.value.length==0)
{
alert("用户名不能为空");
document.my1.a1.focus();
return false;
}
if(document.my1.a2.value!=(document.my1.a3.value))
{
alert("你两次输入的密码不一样,请重新输入")
document.my1.a2.focus();
return false;
}
return true;
}
</script>
</head>

<body>
<form name="my1" id="my1" action="" onsubmit="return checkform2();">
用户名<input type="text" name="a1"&