当页面加载时,使用autofocus属性将光标放置在文本框中。该自动对焦属性是一个布尔属性。如果存在,它指定<input>元素应在页面加载时自动获得焦点。这是一个例子-
<!DOCTYPE html> <html> <body> <form action = "/new.php"> Name: <input type = "text" name = "name" autofocus><br> Subject: <input type = "text" name = "sub"><br> <input type = "submit"> </form> </body> </html>