autofocus屬性是布爾屬性。如果存在,它指定按鈕在頁面加載時應自動獲得焦點。
使用 autofocus 屬性的按鈕:
<!DOCTYPE html>
<html>
<head>
<title>HTML:<button> autofocus 屬性 - 菜鳥教程 (cainiaoplus.com)</title>
<body>
<button type="button" autofocus onclick="alert('Hello world!')">Click Me!</button>
</body>
</html>測試看看 ?/?IEFirefoxOperaChromeSafari
Internet Explorer 10, Firefox, Chrome, 和 Safari 支持autofocus 屬性。
注意: Internet Explorer 9 以及更早IE版本不支持 autofocus 屬性。
autofocus 屬性是一個 boolean(布爾) 屬性。
autofocus 屬性規(guī)定當頁面加載時按鈕應當自動地獲得焦點。
autofocus屬性是HTML5中<button>標記的新屬性。
在 XHTML 中, 不允許屬性簡寫,autofocus 屬性必須定義為 <button autofocus="autofocus">。
<button type="button" autofocus>