开发者

Custom submit function after jQuery Validation

开发者 https://www.devze.com 2023-01-25 16:09 出处:网络
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 submitHa

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消