JavaScript手册
|
【目录】 【上一页】 【下一页】 【索引】
event
The event object contains properties that describe a JavaScript event, and is
passed as an argument to an event handler when the event occurs.
In the case of a mouse-down event, for example, the event object contains the type of event (in this case MouseDown), the x and y position of the cursor at the time of the event, a number representing the mouse button used, and a field containing the modifier keys (Control, Alt, Meta, or Shift) that were depressed at the time of the event. The properties used within the event object vary from one type of event to another. This variation is provided in the描述s of individual event handlers.
For more information, see "General Information about Events".
创建源
event objects are created by Communicator when an event occurs. You do not create them yourself.
安全性
Setting any property of this object requires the UniversalBrowserWrite privilege. In addition, getting the data property of the DragDrop event requires the UniversalBrowserRead privilege. 要获取 Navigator 4.0 中关于安全性更多的信息,请看“JavaScript 指南”中的第七章“JavaScript 安全性”。
属性概览
Not all of these properties are relevant to each event type. To learn which
properties are used by an event, see the "Event object properties used" section
of the individual event handler.
target | String representing the object to which the event was originally sent. (All events) | type | String representing the event type. (All events) | data | Returns an array of strings containing the URLs of the dropped objects. Passed with the DragDrop event. | height | Represents the height of the window or frame. | layerX | Number specifying either the object width when passed with the resize event, or the cursor's horizontal position in pixels relative to the layer in which the event occurred. Note that layerX is synonymous with x. | layerY | Number specifying either the object height when passed with the resize event, or the cursor's vertical position in pixels relative to the layer in which the event occurred. Note that layerY is synonymous with y. | modifiers | String specifying the modifier keys associated with a mouse or key event. Modifier key values are: ALT_MASK, CONTROL_MASK, SHIFT_MASK, and META_MASK. | pageX | Number specifying the cursor's horizontal position in pixels, relative to the page. | pageY | Number specifying the cursor's vertical position in pixels relative to the page. | screenX | Number specifying the cursor's horizontal position in pixels, relative to the screen. | screenY | Number specifying the cursor's vertical position in pixels, relative to the screen. | which | Number specifying either the mouse button that was pressed or the ASCII value of a pressed key. For a mouse, 1 is the left button, 2 is the middle button, and 3 is the right button. | width | Represents the width of the window or frame. |
示例
The following example uses the event object to provide the type of event to the
alert message.
<A HREF="http://home.netscape.com" onClick='alert("Link got an event: " + event.type)'>Click for link event</A>
The following example uses the event object in an explicitly called event handler.
<SCRIPT> function fun1(evnt) { alert ("Document got an event: " + evnt.type); alert ("x position is " + evnt.layerX); alert ("y position is " + evnt.layerY); if (evnt.modifiers & Event.ALT_MASK) alert ("Alt key was down for event."); return true; } document.onmousedown = fun1; </SCRIPT>
【目录】 【上一页】 【下一页】 【索引】
|