Fires when the object receives focus. dhtml语法 Inline HTML | <ELEMENT onfocus = "handler" ... >
| All platforms |
---|
Event property | object.onfocus = handler | JScript only |
---|
object.onfocus = GetRef("handler") | Visual Basic Scripting Edition (VBScript) 5.0 or later only | Named script |
<SCRIPT FOR =
object EVENT = onfocus>
| Internet Explorer only |
---|
Event Information Bubbles | No |
---|
Cancels | No |
---|
To invoke | - Click an object.
- Use keyboard navigation.
- Invoke the focus method.
- invoke the setActive method.
|
---|
Default action |
Sets focus to an object. |
---|
Event Object Properties Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query an event object for data. available properties altKey |
Sets or retrieves a value that indicates the state of the ALT key. |
---|
altLeft |
Sets or retrieves a value that indicates the state of the left ALT key. |
---|
clientX |
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars. |
---|
clientY |
Sets or retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars. |
---|
ctrlLeft |
Sets or retrieves the state of the left CTRL key.
|
---|
offsetX |
Sets or retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event. |
---|
offsetY |
Sets or retrieves the y-coordinate of the mouse pointer's position relative to the object firing the event. |
---|
returnValue |
Sets or retrieves the return value from the event. |
---|
screenX |
Retrieves the x-coordinate of the mouse pointer's position relative to the user's screen. |
---|
screenY |
Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen. |
---|
shiftLeft |
Retrieves the state of the left SHIFT key.
|
---|
srcElement |
Sets or retrieves the object that fired the event. |
---|
type |
Sets or retrieves the event name from the event object. |
---|
x |
Sets or retrieves the x-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element. |
---|
y |
Sets or retrieves the y-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element. |
---|
Remarks
Note Using the setactive method has no effect on document focus. using the 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 activeelement, the onfocus event fires on the object becoming the activeelement only after the 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. as of microsoft® internet explorer 5, elements retain focus within the current browser history when the user returns to a page. to avoid firing the onfocus event unintentionally for an element when the document loads, invoke the 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 tabindex attribute. for internet explorer 5.5 and later, focus on a document, and the active element of a document can be managed separately. the synchronous events onactivate and ondeactivate provide better control for managing activation changes.
DHTML代码范例
This example uses the onfocus event to make input_text and label objects more accessible. when the input_text object has focus, the onfocus event fires and the backgroundcolor, fontsize, and fontweight properties are changed to give the control more prominence. ...
<STYLE>
.normal {background-color:"#FFFFFF"; color:"#000000"; font-weight:normal;
font-size:8pt; font-family:Arial;}
.accessible { background-color:"beige"; font-weight:bold; font-size:10pt;}
</STYLE>
<SCRIPT>
function fnSetStyle(){
event.srcElement.className="accessible";
var oWorkLabel=eval(event.srcElement.id + "_label");
oWorkLabel.className="accessible";
}
</SCRIPT>
<LABEL FOR="oInput" CLASS="normal" ID="oInput_label">Enter some text</LABEL>
<INPUT TYPE="text" CLASS="normal" onfocus="fnSetStyle()" ID="oInput">
... This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.
是否符合公共标准
This event is defined in
HTML 4.0 .
Applies To |
A,
ACRONYM,
ADDRESS,
APPLET,
AREA,
B,
BDO,
BIG,
BLOCKQUOTE,
BUTTON,
CAPTION,
CENTER,
CITE,
CUSTOM,
DD,
DEL,
DFN,
DIR,
DIV,
DL,
DT,
EM,
EMBED,
FIELDSET,
FONT,
FORM,
FRAME,
FRAMESET,
hn,
HR,
I,
IFRAME,
IMG,
INPUT type=button,
INPUT type=checkbox,
INPUT type=file,
INPUT type=hidden,
INPUT type=image,
INPUT type=password,
INPUT type=radio,
INPUT type=reset,
INPUT type=submit,
INPUT type=text,
INS,
ISINDEX,
KBD,
LABEL,
LEGEND,
LI,
LISTING,
MARQUEE,
MENU,
OBJECT,
OL,
P,
PLAINTEXT,
PRE,
Q,
RT,
RUBY,
S,
SAMP,
SELECT,
SMALL,
SPAN,
STRIKE,
STRONG,
SUB,
SUP,
TABLE,
TBODY,
TD,
TEXTAREA,
TFOOT,
TH,
THEAD,
TR,
TT,
U,
UL,
VAR,
window,
XMP | |
更多语法参考 blur, focus, onfocusin
|