Latest web development tutorials

HTML DOM Input Text autofocus 屬性

Input Text 對象參考手冊 Input Text對象參考

實例

查看文本域在頁面加載後是否自動獲取焦點:

var x = document.getElementById("myPassword").autofocus;

x返回結果為:

true

嘗試一下»


定義和用法

autofocus 屬性用於設置或返回頁面在加載後文本域是否自動獲取焦點。

該屬性反映了HTML autofocus 屬性。


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流瀏覽器都支持autofocus 屬性。

注意: Internet Explorer 9及更早IE版本或Opera 12及更早版本的瀏覽器不支持autofocus屬性。


語法

返回autofocus 屬性:

textObject .autofocus

設置autofocus 屬性:

textObject .autofocus=true|false

屬性值

描述
true|false 描述了文本域在頁面加載後是否獲取焦點
  • true - 文本域獲取焦點
  • false - 默認。 文本域不獲取焦點
技術細節
返回值: 布爾值,頁面加載後如果文本域自動獲取焦點返回true,否則返回false。


相關頁面

HTML參考手冊: HTML <input> autofocus屬性


Input Text 對象參考手冊 Input Text對象