给你一个简单的例子:
<html>
<head>
<title>注册新用户</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javaScript">
function Juge(theForm)
{ if (theForm.account.value == "")
{
alert("请输入登录帐号!");
theForm.account.focus();
return (false);
} if (theForm.account.value.length<2)
{
alert("登录帐号至少要2位!");
theForm.account.focus();
return (false);
} if (theForm.password.value.length<3)
{
alert("登录密码至少要3位!");
theForm.password.focus();
return (false);
}
if (theForm.password.value == "")
{
alert("请输入密码!");
theForm.password.focus();
return (false);
}
if (theForm.password.value != theForm.password1.value)
{
alert("您输入的\"密码\"和\"密码确认\"不正确!");
theForm.password.focus();
theForm.password.select();
theForm.password1.value=""
return (false); }
}
</SCRIPT>
</head><body>
<table width="90%" class=tab_m align=center>
<tr class=td_b2002><td align=center height=33><span class=t_w>注册成为网站用户</span></td></tr>
<tr><td>
<table width=750 class=td_b2002d>
<form action="register2.asp" method="post" onSubmit=" return Juge(this)">
<tr>
<td width="368" align="right">登录名</td>
<td width="368"><input type="text" name="account" onblur="if (this.value=='guest') {alert('不允许使用这一用户名注册,请换用其它的用户名。');this.select();this.focus();}">*(必填)</td>
</tr>
<tr>
<td width="368" align="right">密码</td>
<td width="368"><input type="password" name="password">*(必填)</td>
</tr>
<tr>
<td width="368" align="right">确认密码</td>
<td width="368"><input type="password" name="password1">*(必填)</td>
</tr>
</table>
</td></tr></table>
<p align="center"><input type="submit" value="新用户注册">
</form>
</body>
</html>
<html>
<head>
<title>注册新用户</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="javaScript">
function Juge(theForm)
{ if (theForm.account.value == "")
{
alert("请输入登录帐号!");
theForm.account.focus();
return (false);
} if (theForm.account.value.length<2)
{
alert("登录帐号至少要2位!");
theForm.account.focus();
return (false);
} if (theForm.password.value.length<3)
{
alert("登录密码至少要3位!");
theForm.password.focus();
return (false);
}
if (theForm.password.value == "")
{
alert("请输入密码!");
theForm.password.focus();
return (false);
}
if (theForm.password.value != theForm.password1.value)
{
alert("您输入的\"密码\"和\"密码确认\"不正确!");
theForm.password.focus();
theForm.password.select();
theForm.password1.value=""
return (false); }
}
</SCRIPT>
</head><body>
<table width="90%" class=tab_m align=center>
<tr class=td_b2002><td align=center height=33><span class=t_w>注册成为网站用户</span></td></tr>
<tr><td>
<table width=750 class=td_b2002d>
<form action="register2.asp" method="post" onSubmit=" return Juge(this)">
<tr>
<td width="368" align="right">登录名</td>
<td width="368"><input type="text" name="account" onblur="if (this.value=='guest') {alert('不允许使用这一用户名注册,请换用其它的用户名。');this.select();this.focus();}">*(必填)</td>
</tr>
<tr>
<td width="368" align="right">密码</td>
<td width="368"><input type="password" name="password">*(必填)</td>
</tr>
<tr>
<td width="368" align="right">确认密码</td>
<td width="368"><input type="password" name="password1">*(必填)</td>
</tr>
</table>
</td></tr></table>
<p align="center"><input type="submit" value="新用户注册">
</form>
</body>
</html>
我在发表点我的做法,我不喜欢在<form>中进行判断,我喜欢用<onclick>进行判断其实意义都是一样的!!
<input type="submit" value="新用户注册">在这里面进行判断,如:
<input type="submit" value="新用户注册" onclick="return juge(this)">