頁面載入時如何在文字框中放置游標(自動聚焦)?(HTML)


使用 autofocus 屬性可在頁面載入時將游標放在文字框中。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>

更新日期: 1-6-2020

3 千+ 瀏覽量

開啟您的職業生涯

完成課程可獲得認證

開始
廣告
© . All rights reserved.