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

后端 未结 2 475
天涯浪人
天涯浪人 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/

    0 讨论(0)
  • 2020-12-28 20:40

    I don't think its gonna work out.

    Look at the code I left behind

    $('html, body').animate({
        scrollTop: ($('.error').first().offset().top)
    },500);
    
    0 讨论(0)
提交回复
热议问题