Input Number autofocus 属性

定义和用法

autofocus 属性设置或返回页面加载时数字字段是否应自动获得焦点。

此属性反映 HTML autofocus 属性。

另请参阅:

HTML 参考手册:HTML <input> autofocus Attribute

实例

查明数字字段是否在页面加载时自动获得焦点:

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

亲自试一试

语法

返回 autofocus 属性:

numberObject.autofocus

设置 autofocus 属性:

numberObject.autofocus = true|false

属性值

描述
true|false

Specifies whether the numeric field should receive focus when the page is loaded.

  • true - The numeric field receives focus
  • false - Default. The numeric field does not receive focus

Technical Details

Return value: Boolean value, returns if the numeric field automatically receives focus when the page is loaded true; Otherwise return false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support