javascript:验证表单的例子那错了?

来源:百度知道 编辑:UC知道 时间:2024/06/15 02:17:24
<html >
<head>

<title>无标题文档</title>
<script language="javascript" type="text/javascript">
function judge()
{
if (document.form1.nickname.value="")
{alert("请输入你的昵称");}
if (document.form1.qq.value<5&document.form1.qq.value>9)
{alert("请输入你正确的QQ号");}
var mailstr;
mailstr=document.form1.mail.value;
if (mailstr.index("@")=-1)
{alert("请输入你正确的E-mail地址");}
if (document.form1.liuyan.value="")
{alert("请输入留言!");}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
昵称:
<input name="nickname" type="text" id="nickname" size="13" maxlength="20">

QQ号:
<input

if (document.form1.qq.value<5&document.form1.qq.value>9)

这个是他的值,不是位数

应该是 qq.value.length

后一个应该是indexOf

在每个if语句里加上return false
函数最后加上return true
form表单 onSubmit = "return judge()"
提交按钮不要onClick="judge()"

同意楼上千总大人的.

if (document.form1.nickname.value="")
这里是赋值,不是判断值为空。
改if (document.form1.nickname.value=="")

if (document.form1.qq.value<5&document.form1.qq.value>9)
改 if (document.form1.qq.value.lenght<5&document.form1.qq.value.lenght>9)

if (mailstr.index("@")=-1)
改if (mailstr.index("@")==-1)

l楼上说的完全正确