如何在jquery验证器插件中触发错误事件 [英] How to fire an event on error in jquery validator plugin

查看:87
本文介绍了如何在jquery验证器插件中触发错误事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行了jquery验证程序并且页面很长,所以我希望页面向上滚动到顶部,因为我在表单上方的页面顶部显示错误,是否有人知道我可以放置代码的位置对于动画,当表单有错误时会触发吗?

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?

推荐答案

你可以使用 invalidHandler 选项,如下所示:

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);      
  }
});

这篇关于如何在jquery验证器插件中触发错误事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆