JavaScript手册 
目录
此参考中包含
的内容
轻松上手
简介
操作符
语句
核心
文档
窗口
表单
浏览器
事件和
事件句柄
LiveWire
数据库服务
进程管理服务
实用工具
全局函数
LiveConnect
的Java包
索引
 
 
【目录】 【上一页】 【下一页】 【索引】

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.

客户端对象
实现版本Navigator 4.0
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.

targetString representing the object to which the event was originally sent. (All events)
type String representing the event type. (All events)
dataReturns an array of strings containing the URLs of the dropped objects. Passed with the DragDrop event.
heightRepresents the height of the window or frame.
layerXNumber 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.
layerYNumber 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.
modifiersString specifying the modifier keys associated with a mouse or key event. Modifier key values are: ALT_MASK, CONTROL_MASK, SHIFT_MASK, and META_MASK.
pageXNumber specifying the cursor's horizontal position in pixels, relative to the page.
pageYNumber specifying the cursor's vertical position in pixels relative to the page.
screenXNumber specifying the cursor's horizontal position in pixels, relative to the screen.
screenYNumber specifying the cursor's vertical position in pixels, relative to the screen.
whichNumber 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.
widthRepresents 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>


【目录】 【上一页】 【下一页】 【索引】

回页面顶部