EN
이 콘텐츠는 한국어로 제공되지 않아 영어 버전으로 표시됩니다.

autofocus attribute | autofocus property

Provides a way to direct a user to a specific field when a document loads. This can provide both direction and convenience for a user, reducing the need to click or tab to a field when a page opens. This attribute is true when present on an element, and false when missing.

This property is read/write.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4.10.19.4Internet Explorer 10

 

Syntax

HTML
<element autofocus="ptr" ... >

 

JavaScript
object.autofocus = ptr
ptr = object.autofocus

 

Property values

Type: boolean

Returns true if the attribute has been set or is present on the element.

Standards information

Remarks

Only one control in a document can have autofocus specified. If more than one element has the attribute, only the first one in the page will get the focus when the page opens. This is a boolean attribute, requiring only the presence of the attribute to be true.

The following example shows a field that will receive focus when a page opens.

Note  For more code samples, see Form controls part 1 and Form controls part 2: validation on the Windows Internet Explorer sample site.

Examples


<input name="email" type="text" placeholder="joe@contoso.com " autofocus />

See also

HTMLButtonElement
HTMLInputElement
HTMLSelectElement
HTMLTextAreaElement

 

 

표시:
© 2014 Microsoft