Input Text autofocusProperty

Input Text 对象参考手册Input Text Object Reference

Example

Check whether the text field automatically gets focus after the page loads:

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

xThe result is:

true

Try it Yourself »


Definition and Usage

The autofocus property is used to set or return whether the text field automatically gets focus after the page loads.

This property reflects the HTML autofocus attribute.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the autofocus property.

Note:Internet Explorer 9 and earlier IE versions, or Opera 12 and earlier versions, do not support the autofocus property.


Syntax

Return the autofocus property:

textObject.autofocus

Set the autofocus property:

textObject.autofocus=true|false

Property Values

Value Description
true|false Describes whether the text field gets focus after the page loads
  • true - The text field gets focus
  • false - Default. The text field does not get focus
Technical Details
Return Value: A Boolean value, returns true if the text field automatically gets focus after the page loads, otherwise returns false.


Related Pages

HTML Reference:HTML <input> autofocus Attribute


Input Text 对象参考手册Input Text Object Other Extensions