在頁面載入 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>

更新於:2020 年 6 月 1 日

3K+ 瀏覽量

開啟你的 職業道路

完成課程,獲得認證

開始
廣告