共用方式為


onfocus event

Fires when the object receives focus.

 

Syntax

HTML Attribute <element onfocus = "handler(event)">
Event Property object.onfocus = handler;
attachEvent Method object.attachEvent("onfocus", handler)
addEventListener Method object.addEventListener("focus", handler, useCapture)

 

Event information

Synchronous No
Bubbles No
Cancelable No

 

Event handler parameters

Standards information

Remarks

Note  Using the IHTMLElement3::setActive method has no effect on document focus. Using the IHTMLElement2::focus method on an individual element causes the element to gain focus and become the active element.

 

When one object loses activation and another object becomes the IHTMLDocument2::activeElement, the HTMLOptionButtonElementEvents2::onfocus event fires on the object becoming the IHTMLDocument2::activeElement only after the HTMLOptionButtonElementEvents2::onblur event fires on the object losing activation. Use the focus events to determine when to prepare an object to receive input from the user.

Elements cannot receive focus until the document is finished loading.

For Microsoft Internet Explorer 5.5 and later, focus on a document, and the IHTMLDocument2::activeElement of a document can be managed separately. The synchronous events HTMLOptionButtonElementEvents2::onactivate and HTMLOptionButtonElementEvents2::ondeactivate provide better control for managing activation changes.

As of Microsoft Internet Explorer 5, elebrowserments retain focus within the current history when the user returns to a page. To avoid firing the HTMLOptionButtonElementEvents2::onfocus event unintentionally for an element when the document loads, invoke the IHTMLElement2::focus method on another element.

As of Internet Explorer 5, you can force elements that do not implicitly receive focus to receive focus by adding them to the document tabbing order using the IHTMLElement2::tabIndex attribute.

Sets focus to an object.

To invoke this event, do one of the following:

The pEvtObj parameter is required for the following interfaces:

See also

Reference

IHTMLElement2::blur

IHTMLElement2::focus

HTMLOptionButtonElementEvents2::onfocusin