开发者

How to fire an event on error in jquery validator plugin

I have jquery validator running and the开发者_高级运维 page is very long, so I want the page to scroll up to the top because I display errors on the very top of the page above the form, does anyone know where I can put the code for the animation so it fires when the form has errors?


You can use the invalidHandler option for the exact case you want, like this:

$("form").validate({
  rules: { ... rules here ... }
  invalidHandler: function(form, validator) {
    $('html, body').animate({scrollTop: '0px'}, 300);      
  }
});


The same as @Nick suggested, but to use after plugin initialization:

$("form").bind("invalid-form.validate", function() {

});

Its the same that happens internally when the plugin initializes. Source.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜