HTML <input> autofocus 屬性
實(shí)例
設(shè)置 "First name" 輸入字段在頁(yè)面加載時(shí)自動(dòng)獲得焦點(diǎn):
<form action="demo-form.php">
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
First name: <input type="text" name="fname" autofocus><br>
Last name: <input type="text" name="lname"><br>
<input type="submit">
</form>
嘗試一下 ?
瀏覽器支持
Internet Explorer 10、Firefox、Opera、Chrome 和 Safari 支持 autofocus 屬性。
注意:Internet Explorer 9 及之前的版本不支持 <input> 標(biāo)簽的 autofocus 屬性。
定義和用法
autofocus 屬性是一個(gè)布爾屬性。
autofocus 屬性規(guī)定當(dāng)頁(yè)面加載時(shí) <input> 元素應(yīng)該自動(dòng)獲得焦點(diǎn)。
HTML 4.01 與 HTML5之間的差異
autofocus 屬性是 HTML5 中的新屬性。
HTML 與 XHTML 之間的差異
在 XHTML 中,禁止屬性最小化,autofocus 屬性必須定義為 <input autofocus="autofocus" />。
語(yǔ)法
<input autofocus>

更多建議: