Move focus to a particular field

后端 未结 3 631
臣服心动
臣服心动 2021-01-17 17:57

I have a button that will add show a form on the page. how can I move the focus to the first field of the form when that button is clicked?

simple example:

H

3条回答
  •  [愿得一人]
    2021-01-17 18:57

    A quicker lookup would simply be.

    $('#firstField').focus()
    

    However if you removed the ID from your element then this would be better but slightly slower.

    $('#newForm input:first').focus();
    

提交回复
热议问题