HTMLautofocus 屬性
<input> 元素的 autofocus 屬性用於指定哪個 <input> 在網頁載入時獲取焦點。此屬性在 HTML5 中引入。
以下為語法 −
<input autofocus>
現在我們來看一個示例,以便實現 <input> 元素的 autofocus 屬性 −
示例
<!DOCTYPE html> <html> <body> <h2>Log in to your account</h2> <form action="" method="get"> Id: <input type="text" name="id"><br> Password: <input type="password" name="pwd"><br> DOB: <input type="date" name="dob" autofocus><br> <button type="submit" value="Submit">Submit</button> </form> </body> </html>
輸出

在上面的示例中,我們建立了一個表單 −
<form action="" method="get"> Id: <input type="text" name="id"><br> Password: <input type="password" name="pwd"><br> DOB: <input type="date" name="dob" autofocus><br> <button type="submit" value="Submit">Submit</button> </form>
我們已將 autofocus 設定為第三個輸入,如下所示:DOB,因此游標在該處可見 −
DOB: <input type="date" name="dob" autofocus><br>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP