给你一个简单的例子:
<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>
解决方案 »
- 我在用showModalDialog 的时候,浏览器总是打开一个新的标签页,而不是弹出窗口,这个怎么解决?
- IE7下无法加在样式(貌似)
- 如何取得HTML5 Audio元素的播放状态?
- iframe里的页面如何取得父窗口的URL,切iframe里的页面和父页面不是同一个域
- 我想通过表单的Radio项来控制提交到不同的页面,该如何做(跪求)
- Ext4 window的blur事件无效果?
- 如何清除select对象中option 的selected属性?
- 为什么浮动广告上的GIF动画不会动啦???
- javascript中怎么转换成ASCII码??
- AJAX提交表格某一行内容
- 图像转换
- 求解:怎么样在客户短检测用户提交的表单??(急,请看看我的那里错了)
我在发表点我的做法,我不喜欢在<form>中进行判断,我喜欢用<onclick>进行判断其实意义都是一样的!!
<input type="submit" value="新用户注册">在这里面进行判断,如:
<input type="submit" value="新用户注册" onclick="return juge(this)">