&a"/> &a">

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
WBOYforward
2023-09-14 21:53:02984browse

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>

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete