$().ready(function()
{
// $("#myForm").validate();
$("#myForm").validate({
debugger;
rules:{
username:{required:true},
upass1:{required:true},
upass2:{required:true,CheckPWD:true},
usex:{required:true},
uemail:{required:true,email:true}
},
messages:
{
username:{required:'请输入姓名'},
upass1:{required:'请输入密码'},
upass2:{required:'请确认密码',CheckPWD:'两次密码不一致'},
uemail:{required:'请输入邮箱',email:'请输入正确的电子邮件'} ,
usex:{required:'请选择性别'}
},
errorElement:"span",
success:function(label)
{
label.text(" ").addClass("success");
}
});
$("#myForm").submit(function(){
var options=
{//表单提交选项
// beforeSubmit:validate,//表单验证方式
success:CheckResult //提示消息
}
//通过ajax提交表单!
$("#myForm").ajaxSubmit(options);
return false;//防止表单默认提交
});
function CheckResult(data)
{
if(data>0)
{
$("#output1").html("提交成功,欢迎下次再来!");
}else
{
$("#output1").html("提交失败!请刷新在试!返回的数据为"+data);
}
$("#output1").dialog({
modal:true,
buttons:{确认:function(){$(this).dialog('close');}}
});
$("#myForm").resetForm();
}
jQuery.validator.addMethod("CheckPWD",function(value,element)
{
return value==$("#u_pass1").val();//密码比较
});
});
</script>
<body>
<div> 现在的位置>>首页>>注册</div> <div></div>
<hr/>
<form id="myForm" action="doIndex.jsp" method="post">
<td><input type="submit" id="sub1" name="subm" value="确认" /></td>
<td><input type="reset" id="rest1" name="rest" value="取消"/></td>
</tr>
</table>
</form>
<div id="output1"></div>
</body>