Custom submit function after jQuery Validation
How woul开发者_开发问答d I add a custom submit function to a form to prevent it's normal action but so that it only runs after being validated by the jQuery Validation plugin?
You can use the submitHandler
option of .validate()
, like this:
$("form").validate({
submitHandler: function(form) {
//this runs when the form validated successfully
form.submit(); //submit it the form
}
});
There's also an invalidHandler
if you want to run something when it doesn't pass validation.
In the event handler return true
to proceed and return false
to stop.
精彩评论