当前位置:首页 > 设计在线 > 网页设计 > Javascript > Javascript技术之详尽解析event对象

Javascript技术之详尽解析event对象

点击次数:27 次 发布日期:2008-11-26 23:16:48 作者:源代码网
源代码网推荐

源代码网整理以下描述

源代码网整理以下event代表事件的状态,例如触发event对象的元素、鼠标的位置及状态、按下的键等等。

源代码网整理以下event对象只在事件发生的过程中才有效。

源代码网整理以下event的某些属性只对特定的事件有意义。比如,fromElement 和 toElement 属性只对 onmouseover 和 onmouseout 事件有意义。

源代码网整理以下例子

源代码网整理以下下面的例子检查鼠标是否在链接上单击,并且,如果shift键被按下,就取消链接的跳转。

源代码网整理以下<HTML>
<HEAD><TITLE>Cancels Links</TITLE>
<SCRIPT LANGUAGE="JScript">
function cancelLink() {
if (window.event.srcElement.tagName == "A" && window.event.shiftKey)
window.event.returnValue = false;
}
</SCRIPT>
<BODY onclick="cancelLink()">

源代码网整理以下下面的例子在状态栏上显示鼠标的当前位置。

源代码网整理以下<BODY onmousemove="window.status = "X=" + window.event.x + " Y=" + window.event.y">

源代码网整理以下
属性:

源代码网整理以下altKey, button, cancelBubble, clientX, clientY, ctrlKey, fromElement, keyCode, offsetX, offsetY, propertyName, returnValue, screenX, screenY, shiftKey, srcElement, srcFilter, toElement, type, x, y

源代码网整理以下--------------------------------------------------------------------------------

源代码网整理以下1.altKey
描述:
检查alt键的状态。

源代码网整理以下语法:
event.altKey

源代码网整理以下可能的值:
当alt键按下时,值为 TRUE ,否则为 FALSE 。只读。

源代码网整理以下
2.button
描述:
检查按下的鼠标键。

源代码网整理以下语法:
event.button

源代码网整理以下可能的值:
0 没按键
1 按左键
2 按右键
3 按左右键
4 按中间键
5 按左键和中间键
6 按右键和中间键
7 按所有的键

源代码网整理以下这个属性仅用于onmousedown, onmouseup, 和 onmousemove 事件。对其他事件,不管鼠标状态如何,都返回 0(比如onclick)。

源代码网整理以下
源代码网供稿.

网友评论 (0)
会员中心
设计在线
本站推荐
设计在线之精华