如何在 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>
廣告