JQuery Validation PlugIn - submitHandler syntax

2019-08-10 06:01发布

问题:

I am using asp.net mvc 3 client validation. I am trying to do some stuff before any form is submitted. I found JQuery's validation has a submitHandler that seems to be what I am looking for but I am having problems with the syntax. T

I've tried the following but I get a syntax error.

 $(function () {
    submitHandler: function (form) {
      //my logic
      alert('here');
    }
  });

Thanks for any help!!!

回答1:

You need to call this as part of the .validate() options, like this:

$(function() {
  $("#formID").validate({
    submitHandler: function(form) {
      //my logic
      alert('here');
    }
  });
});