<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册</title>
<script language=“javascript”>
function check(){
if(document.form1.pass.value!=document.form1.confirm.value)
{
window.alter("password wrong");
document.form1.pass.focus();
return false;
}
if(document.form1.user.value=="")
{
window.alter("no name");
document.form1.user.focus();
return false;
}
if(document.form1.pass.value.length<6)
{
{
window.alter("password too short");
document.form1.pass.focus();
return false;
}
document.form1.submit();
}
</script>
</head>
<body>
<form method="get" name="form1" action="formdeal.jsp">
<p>user:<input type="text" name="user" size="16">
</p>
<p>password:<input type="password" name="pass" size="16">
</p>
<p>确认password:<input type="password" name="confirm" size="16">
</p>
<br>
<br>
<p><input type="submit" value="提交" name="提交" onclick="check()">
<input type="reset" value="全部重写" name="重置" onclick="check()">
</p>
</form>
</body>
</html>
这段代码出不来出错对话框,是那出错啦,指教那!!!!!!!!!!!
<script language="javascript"> 双引号不是英文状态下的!
在第一个if() 左括号不是英文状态下的!
window.alter 写错了 window.alert();
最后一个if 里多个左大括号
错误不提交最好写到form里 onsubmit="return check()" 在下面写不起作用!正确的如下!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>注册</title>
<script language="javascript">
function check(){
if(document.form1.pass.value!=document.form1.confirm.value)
{
window.alert("password wrong");
document.form1.pass.focus();
return false;
}
if(document.form1.user.value=="")
{
window.alert("no name");
document.form1.user.focus();
return false;
}
if(document.form1.pass.value.length<6)
{
window.alert("password too short");
document.form1.pass.focus();
return false;
}
document.form1.submit();
}
</script>
</head>
<body>
<form method="get" name="form1" action="" onsubmit="return check()" >
<p>user:<input type="text" name="user" size="16">
</p>
<p>password:<input type="password" name="pass" size="16">
</p>
<p>确认password:<input type="password" name="confirm" size="16">
</p>
<br>
<br>
<p><input type="submit" value="提交" name="提交" >
<input type="reset" value="全部重写" name="重置" >
</p>
</form>
</body>
</html>
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息