如何在 HTML 中指定元素在頁面載入時自動獲得焦點?


使用 autofocus 屬性可在 HTML 中指定元素在頁面載入時自動獲得焦點 -

示例

你可以嘗試執行以下程式碼來學習如何在 HTML 中實現 autofocus 屬性 -

<!DOCTYPE html>
<html>
   <body>
      <p>Click on the below button to generate an alert box.</p>
      <button type = "button" autofocus onclick = "alert('Welcome!')">Result</button>
   </body>
</html>

更新時間: 2020 年 3 月 2 日

197 次瀏覽

開始你的 職業生涯

完成課程獲得認證

開始
廣告