表单加载时如何关注无输入?

时间:2018-01-27 22:55:42

标签: html forms

当表单加载时,如何确保没有输入聚焦?目前默认情况下,它似乎专注于我的第一个输入元素。

<form>
  <input>  <-- When I load the page, this input is focused.
  <input>
  <input>
<form>

我不确定原因,但是有两个人要求提供更多代码和一个有效的例子吗?所以这就是整个项目!

的index.html:

<!DOCTYPE html>
  <html>
    <body>
      <form>
        First name: <input type="text" name="fname">
        Last name: <input type="text" name="lname">
     </form>
   </body>
 </html>

当页面加载时,第一个输入被聚焦。我希望没有任何投入可以集中注意力。我对这种困惑感到有些困惑......

1 个答案:

答案 0 :(得分:0)

创建这样的另一个输入。

<input style="display:none;" aria-hidden="true" autofocus></input>

细分:使输入不可见,然后制作,以便屏幕阅读器不会读取它,最后,让它绘制焦点。