Home > Web Front-end > HTML Tutorial > How can I position the cursor (auto focus) in a text box when the page loads?

How can I position the cursor (auto focus) in a text box when the page loads?

WBOY
Release: 2023-09-14 21:53:02
forward
972 people have browsed it

How can I position the cursor (auto focus) in a text box when the page loads?

When the page loads, use the autofocus attribute to place the cursor in the text box. autofocus The property is a Boolean property. If present, it specifies that the element should automatically receive focus when the page loads. Here is an example -

Example

<!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>
Copy after login

The above is the detailed content of How can I position the cursor (auto focus) in a text box when the page loads?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template