When form is validated, how to SCROLL to the first error instead of jumping?

后端 未结 6 733
一向
一向 2021-01-30 01:34

I\'ve seen many questions with variations on this theme, but I\'m looking for the straightforward solution:

HTML form, jQuery validation, multiple fields are required. W

6条回答
  •  余生分开走
    2021-01-30 02:16

    I dont like all the jQuery extentions so here is my solution to this problem:

    if ($('#MYID').valid()) {
          //dosomething();
    } else {
        $('html, body').animate({
             scrollTop: ($('.error').offset().top - 300)
        }, 2000);
    }
    

提交回复
热议问题