我有一个 Jquery 验证插件问题:
当表单刚刚生效时(错误信息刚刚消失),第一次提交点击不起作用,我需要再次点击才能使其正常工作。我想当表格刚刚生效时,它仍然处于“不可提交”模式。请问在验证后是否可以从第一次点击开始工作?非常感谢你 !
<html>
<head>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/additional-methods.js"></script>
</head>
<body>
<div class="row-fluid" id="top">
<!--top-->
</div>
<div class="row-fluid">
<form id="signInForm">
<label class="control-label" for="usermail">e-mail</label>
<input type="text" id="usermail" name="usermail">
<span class="errMsg">*</span>
<label class="control-label" for="pass">Password</label>
<input type="password" id="pass" name="pass">
<span class="errMsg">*</span>
<button type="submit">Sign In</button>
</form>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#signInForm').validate({
debug: false,
rules: { usermail:{required:true,email:true,remote:"Ajax_isSigned.php"},
pass:"required"
},
messages: { usermail:{required:"Required !",email:"wrong format",remote:"mail never been registered"},
pass:"Required !"
},
submitHandler: function(){submitForm()}
})// End of validate()
}); // End of $(document).ready
function submitForm(){
$("#signInForm").submit(function(event) {
$.ajax({
type: "POST",
url: "Ajax_Login2.php",
data: $(this).serialize(),
success: function(html){ if(html=='success'){;$('#top').text('OK')}}
});// end of $.ajax
return false;
});
}
</script>
</body>
</html>
好的,这是经过所有帮助后的最终和经过测试的工作代码:
$('#signInForm').validate({
debug: false,
errorElement:"span",
errorClass:"errMsg",
onfocusout: function () {$('#usermail').valid();}, // only check on focusout, NOT onChange.
onkeyup: function () {$('#pass').valid()}, // check on onChange.
submitHandler: function(){submitForm();return false;
},
rules: {
usermail:{required:true,email:true,remote:"Ajax_isSigned.php"},
pass:"required"
},
messages: {
usermail:{required:"Required !",email:"wrong format",remote:"mail never been registered"},
pass:"Required !"
}
})// End of validate()
function submitForm(){
$.ajax({
type: "POST",
url: "Ajax_Login.php",
data: $('#signInForm').serialize(),
success: function(html){
if(html=='success'){$('#top').append('OK<br>')}
if(html=='fail'){$('#top').append('NG<br>')}
}
});// end of $.ajax
}// end of submitForm()