如何指定元素應該在頁面載入時在 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>

更新於: 02-Mar-2020

197 次瀏覽

開啟您的 職業生涯

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.