jquery scroll to specific div position in case of error and focus

后端 未结 2 486
天涯浪人
天涯浪人 2020-12-28 20:18

I have a hidden div with specific error messages throughout my form. Before form submit I run a validate routine to check if all the required fields are filled with some tex

2条回答
  •  再見小時候
    2020-12-28 20:36

    var errorDiv = $('.redAlert:visible').first();
    var scrollPos = errorDiv.offset().top;
    $(window).scrollTop(scrollPos);
    

    Demo: http://jsfiddle.net/Cjuve/2/

提交回复
热议问题