How to focus first input?

前端 未结 3 806
日久生厌
日久生厌 2021-01-29 05:49

I have a ASP.NET MVC application and I want to focus the first field in error. On submit, if the last field has error and user tries to submit the form, the focus is going to th

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 06:40

    You can use eq method.

    eq method reduces the set of matched elements to the one at the specified index.

    $('.input-validation-error').eq(0).focus();
    

提交回复
热议问题