前台页面 <form name="myform" method="post" action="Register_f.asp" onsubmit="return check_register()">
<table width="90%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="17%" height="40" align="right" class="fb">电子邮箱 </td>
<td width="60%" align="left"><input name="email" id="email" type="text" class="inp" size="30" maxlength="100" onblur="chk_email(this.value)" /><label id="emailInfo"></label></td>
<td width="23%" align="left"><a href="#" class="blue12link">我没有邮箱</a></td>
</tr>
<tr>
<td height="40" align="right" class="fb">用户名</td>
<td colspan="2" align="left"><input name="username" id="username" type="text" class="inp" size="30" maxlength="100" onblur="chk_user(this.value)"/><label id="userInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">创建密码</td>
<td colspan="2" align="left"><input name="pass" id="pass" type="password" class="inp" size="30" maxlength="100" onblur="chk_pwd(this.value)"/><label id="pwdInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">确认密码</td>
<td colspan="2" align="left"><input name="querenpass" id="querenpass" type="text" class="inp" size="30" maxlength="100" onblur="chk_repwd(this.value)"/><label id="repwdInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">验证码</td>
<td colspan="2" align="left"> </td>
</tr>
<tr>
<td height="40" align="right" class="fb"> </td>
<td colspan="2" align="left"><input name="checkbox" type="checkbox" value="checkbox" checked="checked" />
我已看过并同意<a href="#" class="blue12link">《徐州英才网用户相关协议》</a></td>
</tr>
<tr>
<td height="40" align="right" class="fb"> </td>
<td colspan="2" align="left"><input type="image" name="image" src="../images/quick.gif" /></td>
</tr>
</table>
</form>后台function chk_user(value)
{
$('#userInfo').html('');
if(value == '') {
$('#userInfo').html('*用户名为空,请重新输入');
$('#userInfo').css('color','red');
$('#userInfo').focus();
return false;
}
var pattern=/^[a-zA-Z](\w){4,17}$/;
if(!pattern.test(value))
{
$('#username').css('color','red');
$('#userInfo').html('*请重新输入用户名');
$('#userInfo').css('color','red');
$('#userInfo').focus();
return false;
}
}function chk_email(email)
{
$('#emailInfo').html('');
if(email == '') {
$('#emailInfo').html('*请输入你的Email地址');
$('#emailInfo').css('color','red');
$('#emailInfo').focus();
return false;
}
var pattern = /^\w+@[a-zA-Z0-9]+(\.[a-zA-Z]{1,3})(\.[a-zA-Z]{1,3})?$/;
if(!pattern.test(email)) {
$('#email').css('color','red');
$('#emailInfo').html('*你的Email格式错误,请重新输入');
$('#emailInfo').css('color','red');
$('#emailInfo').focus();
return false;
}
}function chk_pwd(pwd)
{
$('#pwdInfo').html('');
if(pwd == '') {
$('#pwdInfo').html('*请输入密码');
$('#pwdInfo').css('color','red');
$('#pwdInfo').focus();
return false;
} else if (pwd.length<6) {
$('#pwdInfo').html('密码必须大于6个字符,请重新输入');
$('#pwdInfo').css('color','red');
$('#pwdInfo').focus();
return false;
} else if(pwd.length>18) {
$('#pwdInfo').html('密码必须小于18个字符,请重新输入');
$('#pwdInfo').css('color','red');
$('#pwdInfo').focus();
return false;
}
else {
$('#pwd').css('color','green'); $('#pwdInfo').css('color','green');
$('#pwdInfo').html('正确');
}}function chk_repwd(repwd)
{
$('#repwdInfo').html('');
if(repwd == '') {
$('#repwdInfo').html('*请再次输入密码');
$('#repwdInfo').css('color','red');
$('#repwdInfo').focus();
return false;
}
if ($('#pass').val() != repwd) {
$('#repwdInfo').html('两次输入的密码不一致,请重新输入');
$('#repwdInfo').css('color','red');
$('#repwdInfo').focus();
return false;
}
if( $('#pass').val() == $('#querenpass').val() ){
$('#repwd').css('color','green'); $('#repwdInfo').css('color','green');
$('#repwdInfo').html('正确');
}}
function check_register() {
$('#registerck').html('');
if(chk_user($('#username').val())&& chk_email($('#email').val()) && chk_pwd($('#pass').val()) && chk_repwd($('#querenpass').val())) {
return true;
}else {
$('#registerck').html("信息不完整,请重新填写");
$('#registerck').css('color','red');
return false;
}
}
为空可以验证 ,填写OK 按钮点了也没反应 ~~~
<table width="90%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="17%" height="40" align="right" class="fb">电子邮箱 </td>
<td width="60%" align="left"><input name="email" id="email" type="text" class="inp" size="30" maxlength="100" onblur="chk_email(this.value)" /><label id="emailInfo"></label></td>
<td width="23%" align="left"><a href="#" class="blue12link">我没有邮箱</a></td>
</tr>
<tr>
<td height="40" align="right" class="fb">用户名</td>
<td colspan="2" align="left"><input name="username" id="username" type="text" class="inp" size="30" maxlength="100" onblur="chk_user(this.value)"/><label id="userInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">创建密码</td>
<td colspan="2" align="left"><input name="pass" id="pass" type="password" class="inp" size="30" maxlength="100" onblur="chk_pwd(this.value)"/><label id="pwdInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">确认密码</td>
<td colspan="2" align="left"><input name="querenpass" id="querenpass" type="text" class="inp" size="30" maxlength="100" onblur="chk_repwd(this.value)"/><label id="repwdInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">验证码</td>
<td colspan="2" align="left"> </td>
</tr>
<tr>
<td height="40" align="right" class="fb"> </td>
<td colspan="2" align="left"><input name="checkbox" type="checkbox" value="checkbox" checked="checked" />
我已看过并同意<a href="#" class="blue12link">《徐州英才网用户相关协议》</a></td>
</tr>
<tr>
<td height="40" align="right" class="fb"> </td>
<td colspan="2" align="left"><input type="image" name="image" src="../images/quick.gif" /></td>
</tr>
</table>
</form>后台function chk_user(value)
{
$('#userInfo').html('');
if(value == '') {
$('#userInfo').html('*用户名为空,请重新输入');
$('#userInfo').css('color','red');
$('#userInfo').focus();
return false;
}
var pattern=/^[a-zA-Z](\w){4,17}$/;
if(!pattern.test(value))
{
$('#username').css('color','red');
$('#userInfo').html('*请重新输入用户名');
$('#userInfo').css('color','red');
$('#userInfo').focus();
return false;
}
}function chk_email(email)
{
$('#emailInfo').html('');
if(email == '') {
$('#emailInfo').html('*请输入你的Email地址');
$('#emailInfo').css('color','red');
$('#emailInfo').focus();
return false;
}
var pattern = /^\w+@[a-zA-Z0-9]+(\.[a-zA-Z]{1,3})(\.[a-zA-Z]{1,3})?$/;
if(!pattern.test(email)) {
$('#email').css('color','red');
$('#emailInfo').html('*你的Email格式错误,请重新输入');
$('#emailInfo').css('color','red');
$('#emailInfo').focus();
return false;
}
}function chk_pwd(pwd)
{
$('#pwdInfo').html('');
if(pwd == '') {
$('#pwdInfo').html('*请输入密码');
$('#pwdInfo').css('color','red');
$('#pwdInfo').focus();
return false;
} else if (pwd.length<6) {
$('#pwdInfo').html('密码必须大于6个字符,请重新输入');
$('#pwdInfo').css('color','red');
$('#pwdInfo').focus();
return false;
} else if(pwd.length>18) {
$('#pwdInfo').html('密码必须小于18个字符,请重新输入');
$('#pwdInfo').css('color','red');
$('#pwdInfo').focus();
return false;
}
else {
$('#pwd').css('color','green'); $('#pwdInfo').css('color','green');
$('#pwdInfo').html('正确');
}}function chk_repwd(repwd)
{
$('#repwdInfo').html('');
if(repwd == '') {
$('#repwdInfo').html('*请再次输入密码');
$('#repwdInfo').css('color','red');
$('#repwdInfo').focus();
return false;
}
if ($('#pass').val() != repwd) {
$('#repwdInfo').html('两次输入的密码不一致,请重新输入');
$('#repwdInfo').css('color','red');
$('#repwdInfo').focus();
return false;
}
if( $('#pass').val() == $('#querenpass').val() ){
$('#repwd').css('color','green'); $('#repwdInfo').css('color','green');
$('#repwdInfo').html('正确');
}}
function check_register() {
$('#registerck').html('');
if(chk_user($('#username').val())&& chk_email($('#email').val()) && chk_pwd($('#pass').val()) && chk_repwd($('#querenpass').val())) {
return true;
}else {
$('#registerck').html("信息不完整,请重新填写");
$('#registerck').css('color','red');
return false;
}
}
为空可以验证 ,填写OK 按钮点了也没反应 ~~~
<input type="image" name="image" src="../images/quick.gif" />
<form name="myform" method="post" action="Register_f.asp" onsubmit="return check_register()">
<table width="90%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td width="17%" height="40" align="right" class="fb">电子邮箱 </td>
<td width="60%" align="left"><input name="email" id="email" type="text" class="inp" size="30" maxlength="100" onblur="chk_email(this.value)" /><label id="emailInfo"></label></td>
<td width="23%" align="left"><a href="#" class="blue12link">我没有邮箱</a></td>
</tr>
<tr>
<td height="40" align="right" class="fb">用户名</td>
<td colspan="2" align="left"><input name="username" id="username" type="text" class="inp" size="30" maxlength="100" onblur="chk_user(this.value)"/><label id="userInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">创建密码</td>
<td colspan="2" align="left"><input name="pass" id="pass" type="password" class="inp" size="30" maxlength="100" onblur="chk_pwd(this.value)"/><label id="pwdInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">确认密码</td>
<td colspan="2" align="left"><input name="querenpass" id="querenpass" type="text" class="inp" size="30" maxlength="100" onblur="chk_repwd(this.value)"/><label id="repwdInfo"></label></td>
</tr>
<tr>
<td height="40" align="right" class="fb">验证码</td>
<td colspan="2" align="left"> </td>
</tr>
<tr>
<td height="40" align="right" class="fb"> </td>
<td colspan="2" align="left"><input name="checkbox" type="checkbox" value="checkbox" checked="checked" />
我已看过并同意<a href="#" class="blue12link">《徐州英才网用户相关协议》</a></td>
</tr>
<tr>
<td height="40" align="right" class="fb"> </td>
<td colspan="2" align="left"><<input type="image" name="image" src="../images/quick.gif" /><!--加上这个,你再试一试~~~-->
<<input type="submit" value="提交" name="submit"/>
/td>
</tr>
</table>
</form>
哈哈,对按钮来说,type="submit"的按钮 才会触发表单的onsubmit哦~~~
function chk_user(value)
{
$('#userInfo').html('');
if(value == '') {
$('#userInfo').html('*用户名为空,请重新输入');
$('#userInfo').css('color','red');
$('#userInfo').focus();
return false;
}else {
$('#userInfo').html('');//当验证通过的情况下,清空提示信息,并返回值
return true;
}
var pattern=/^[a-zA-Z](\w){4,17}$/;
if(!pattern.test(value))
{
$('#username').css('color','red');
$('#userInfo').html('*请重新输入用户名');
$('#userInfo').css('color','red');
$('#userInfo').focus();
return false;
}else {
$('#userInfo').html('');//当验证通过的情况下,清空提示信息,并返回值
return true;
}
return true;//这句执行不到,可以忽略,要上面即可
}
onsubmit="return check_register()">//这里不改