focus() to input without scrolling

后端 未结 7 881
有刺的猬
有刺的猬 2020-12-08 18:03

I have a search input text which I\'d like to apply a focus() when loading the page, the problem is that the focus function automatically does a sc

7条回答
  •  长情又很酷
    2020-12-08 18:52

    As of today, the preferred way to set the focus on an element upon page load is using the autofocus attribute. This does not involve any scrolling.

    The autofocus attrubute is part of the HTML5 standard and is supported by all major browsers, with the only notable exception of Internet Explorer 9 or earlier.

提交回复
热议问题