event对象小结| darkmi'blog

event瀵硅薄姒傝堪
Javascript鐨凟vent瀵硅薄鐢ㄦ潵鎻忚堪Javascript鐨勪簨浠讹紝瀹冧富瑕佷綔鐢ㄤ簬IE4鍜孨N4浠ュ悗鐨勫悇涓祻瑙堝櫒鐗堟湰涓€?

Event浠h〃浜嬩欢鐘舵€侊紝濡備簨浠跺彂鐢熺殑鍏冪礌锛岄敭鐩樼姸鎬侊紝榧犳爣浣嶇疆鍜岄紶鏍囨寜閽姸鎬併€備竴鏃︿簨浠跺彂鐢?渚夸細鐢熸垚Event瀵硅薄锛屽鍗曞嚮涓€涓寜閽紝娴忚鍣ㄧ殑鍐呭瓨涓氨浜х敓鐩稿簲鐨?event瀵硅薄銆?

娉ㄦ剰锛?/strong>
锛?锛塭vent浠h〃浜嬩欢鐨勭姸鎬侊紝渚嬪瑙﹀彂event瀵硅薄鐨勫厓绱犮€侀紶鏍囩殑浣嶇疆鍙婄姸鎬併€佹寜涓嬬殑閿瓑绛夈€?br /> 锛?锛塭vent瀵硅薄鍙湪浜嬩欢鍙戠敓鐨勮繃绋嬩腑鎵嶆湁鏁堛€?br /> 锛?锛塭vent鐨勬煇浜涘睘鎬у彧瀵圭壒瀹氱殑浜嬩欢鏈夋剰涔夈€傛瘮濡傦紝fromElement 鍜?toElement 灞炴€у彧瀵?onmouseover 鍜?onmouseout 浜嬩欢鏈夋剰涔夈€?/p>

涓嬮潰鐨勪緥瀛愬睍绀轰簡鍦ㄤ簨浠剁殑鏈彂鐢熺殑鏃跺€檈vent瀵硅薄骞朵笉瀛樺湪锛?/p>

<html>
<head>
<title>event test</title>

<script type="text/javascript">
alert(window.event);
alert(Event);
</script>
</head>

<body>
</body>
</html>

绗竴涓猘lert涓簄ull锛岀浜屼釜alert涓衡€滄湭瀹氫箟鈥濄€?/p>

鍙湁鍦ㄤ簨浠剁殑鍙戠敓杩囩▼涓簨浠舵墠鏈夋晥锛?/p>

鍦ㄩ紶鏍囧崟鍑绘椂鏄剧ずevent浜嬩欢銆?/p>

event瀵硅薄鐨勫睘鎬?/strong>

锛?锛変笌浣嶇疆鐩稿叧鐨勫睘鎬э細
x鈥?y锛宑lientX鈥?clientY鈥?offsetX鈥?offsetY鈥?screenX鈥?screenY鈥?/p>

1. x
鎻忚堪锛?br /> 杩斿洖榧犳爣鐩稿浜巆ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌鐨剎杞村潗鏍囥€傚鏋滄病鏈塩ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌锛岄粯璁や互BODY鍏冪礌浣滀负鍙傝€冨璞°€?br /> 璇硶锛?br /> event.x
娉ㄩ噴锛?br /> 濡傛灉浜嬩欢瑙﹀彂鍚庯紝榧犳爣绉诲嚭绐楀彛澶栵紝鍒欒繑鍥炵殑鍊间负 -1
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>

2. y
鎻忚堪锛?br /> 杩斿洖榧犳爣鐩稿浜巆ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌鐨剏杞村潗鏍囥€傚鏋滄病鏈塩ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌锛岄粯璁や互BODY鍏冪礌浣滀负鍙傝€冨璞°€?br /> 璇硶锛?br /> event.y
娉ㄩ噴锛?br /> 濡傛灉浜嬩欢瑙﹀彂鍚庯紝榧犳爣绉诲嚭绐楀彛澶栵紝鍒欒繑鍥炵殑鍊间负 -1
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?

3.clientX
鎻忚堪锛?br /> 杩斿洖榧犳爣鍦ㄧ獥鍙e鎴峰尯鍩熶腑鐨刋鍧愭爣銆?br /> 璇硶锛?br /> event.clientX
娉ㄩ噴锛?br /> 杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>

4.clientY
鎻忚堪锛?br /> 杩斿洖榧犳爣鍦ㄧ獥鍙e鎴峰尯鍩熶腑鐨刌鍧愭爣銆?br /> 璇硶锛?br /> event.clientY
娉ㄩ噴锛?br /> 杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>

5.offsetX
鎻忚堪锛?br /> 妫€鏌ョ浉瀵逛簬瑙﹀彂浜嬩欢鐨勫璞★紝榧犳爣浣嶇疆鐨勬按骞冲潗鏍?br /> 璇硶锛?br /> event.offsetX

6.offsetY
鎻忚堪锛?br /> 妫€鏌ョ浉瀵逛簬瑙﹀彂浜嬩欢鐨勫璞★紝榧犳爣浣嶇疆鐨勫瀭鐩村潗鏍?br /> 璇硶锛?br /> event.offsetY

13.screenX
鎻忚堪锛?br /> 妫€娴嬮紶鏍囩浉瀵逛簬鐢ㄦ埛灞忓箷鐨勬按骞充綅缃?br /> 璇硶锛?br /> event.screenX
娉ㄩ噴锛?br /> 杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>

14.screenY
鎻忚堪锛?br /> 妫€娴嬮紶鏍囩浉瀵逛簬鐢ㄦ埛灞忓箷鐨勫瀭鐩翠綅缃?br /> 璇硶锛?br /> event.screenY
娉ㄩ噴锛?br /> 杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>

涓庡姛鑳介敭鏈夊叧鐨勫睘鎬э細
ctrlKey鈥?shiftKey鈥?altKey鈥?

1.ctrlKey
鎻忚堪锛?br /> 妫€鏌trl閿殑鐘舵€併€?br /> 璇硶锛?br /> event.ctrlKey
鍙兘鐨勫€硷細
褰揷trl閿寜涓嬫椂锛屽€间负 TRUE 锛屽惁鍒欎负 FALSE 銆傚彧璇汇€?/p>

2.altKey
鎻忚堪锛?br /> 妫€鏌lt閿殑鐘舵€併€?br /> 璇硶锛?br /> event.altKey
鍙兘鐨勫€硷細
褰揳lt閿寜涓嬫椂锛屽€间负 TRUE 锛屽惁鍒欎负 FALSE 銆傚彧璇汇€?/p>

3.shiftKey
鎻忚堪锛?br /> 妫€鏌hift閿殑鐘舵€併€?br /> 璇硶锛?br /> event.shiftKey
鍙兘鐨勫€硷細
褰搒hift閿寜涓嬫椂锛屽€间负 TRUE 锛屽惁鍒欎负 FALSE 銆傚彧璇汇€?/p>

鍏朵粬灞炴€э細
button鈥?srcElement鈥?fromElement鈥?toElement鈥?keyCode鈥?br /> srcFilter鈥?cancelBubble鈥?propertyName鈥?returnValue鈥? type鈥?

1.button
鎻忚堪锛?br /> 妫€鏌ユ寜涓嬬殑榧犳爣閿€?br /> 璇硶锛?br /> event.button
鍙兘鐨勫€硷細
0 娌℃寜閿?br /> 1 鎸夊乏閿?br /> 2 鎸夊彸閿?br /> 3 鎸夊乏鍙抽敭
4 鎸変腑闂撮敭
5 鎸夊乏閿拰涓棿閿?br /> 6 鎸夊彸閿拰涓棿閿?br /> 7 鎸夋墍鏈夌殑閿?br /> 杩欎釜灞炴€т粎鐢ㄤ簬onmousedown鈥?onmouseup鈥?鍜?onmousemove 浜嬩欢銆傚鍏朵粬浜嬩欢锛屼笉绠¢紶鏍囩姸鎬佸浣曪紝閮借繑鍥?0锛堟瘮濡俹nclick锛夈€?/p>

2.srcElement
鎻忚堪锛?br /> 杩斿洖瑙﹀彂浜嬩欢鐨勫厓绱犮€傚彧璇汇€?br /> 璇硶锛?br /> event.srcElement

3.toElement
鎻忚堪锛?br /> 妫€娴?onmouseover 鍜?onmouseout 浜嬩欢鍙戠敓鏃讹紝榧犳爣鎵€杩涘叆鐨勫厓绱犮€?鍙傝€冿細7.fromElement
璇硶锛?br /> event.toElement
娉ㄩ噴锛?br /> 杩欐槸涓彧璇诲睘鎬с€?/p>

4.fromElement
鎻忚堪锛?br /> 妫€娴?onmouseover 鍜?onmouseout 浜嬩欢鍙戠敓鏃讹紝榧犳爣鎵€绂诲紑鐨勫厓绱犮€?鍙傝€冿細18.toElement
璇硶锛?br /> event.fromElement
娉ㄩ噴锛?br /> 杩欐槸涓彧璇诲睘鎬с€?/p>

5.keyCode
鎻忚堪锛?br /> 妫€娴嬮敭鐩樹簨浠剁浉瀵瑰簲鐨勫唴鐮併€?br /> 杩欎釜灞炴€х敤浜?onkeydown鈥?onkeyup鈥?鍜?onkeypress 浜嬩欢銆?br /> 璇硶锛?br /> event.keyCode[ = keyCode]
鍙兘鐨勫€硷細
杩欐槸涓彲璇诲啓鐨勫€硷紝鍙互鏄换浣曚竴涓猆nicode閿洏鍐呯爜銆傚鏋滄病鏈夊紩鍙戦敭鐩樹簨浠讹紝鍒欒鍊间负 0 銆?/p>

6.srcFilter
鎻忚堪锛?br /> 杩斿洖瑙﹀彂 onfilterchange 浜嬩欢鐨勬护闀溿€傚彧璇汇€?br /> 璇硶锛?br /> event.srcFilter

7.cancelBubble
鎻忚堪锛?br /> 妫€娴嬫槸鍚︽帴鍙椾笂灞傚厓绱犵殑浜嬩欢鐨勬帶鍒躲€?br /> 璇硶锛?br /> event.cancelBubble[ = cancelBubble]
鍙兘鐨勫€硷細
杩欐槸涓€涓彲璇诲啓鐨勫竷灏斿€?
TRUE 涓嶈涓婂眰鍘熺礌鐨勪簨浠舵帶鍒躲€?br /> FALSE 鍏佽琚笂灞傚厓绱犵殑浜嬩欢鎺у埗銆傝繖鏄粯璁ゅ€笺€?/p>

8.propertyName
鎻忚堪锛?br /> 璁剧疆鎴栬繑鍥炲厓绱犵殑鍙樺寲浜嗙殑灞炴€х殑鍚嶇О銆?br /> 璇硶锛?br /> event.propertyName [ = sProperty ]
鍙兘鐨勫€硷細
sProperty 鏄竴涓瓧绗︿覆锛屾寚瀹氭垨杩斿洖瑙﹀彂浜嬩欢鐨勫厓绱犲湪浜嬩欢涓彉鍖栦簡鐨勫睘鎬х殑鍚嶇О銆?br /> 杩欎釜灞炴€ф槸鍙鍐欑殑銆傛棤榛樿鍊笺€?br /> 娉ㄩ噴锛?br /> 浣犲彲浠ラ€氳繃浣跨敤 onpropertychange 浜嬩欢锛屽緱鍒?propertyName 鐨勫€笺€?/p>

9.returnValue
鎻忚堪锛?br /> 璁剧疆鎴栨鏌ヤ粠浜嬩欢涓繑鍥炵殑鍊?br /> 璇硶锛?br /> event.returnValue[ = Boolean]
鍙兘鐨勫€硷細
true 浜嬩欢涓殑鍊艰杩斿洖
false 婧愬璞′笂浜嬩欢鐨勯粯璁ゆ搷浣滆鍙栨秷
渚嬪瓙瑙佹湰鏂囩殑寮€澶淬€?/p>

10.type
鎻忚堪锛?br /> 杩斿洖浜嬩欢鍚嶃€?br /> 璇硶锛?br /> event.type
娉ㄩ噴锛?br /> 杩斿洖娌℃湁鈥渙n鈥濅綔涓哄墠缂€鐨勪簨浠跺悕锛屾瘮濡傦紝onclick浜嬩欢杩斿洖鐨則ype鏄痗lick
鍙銆?/p>

涓€涓簨浠剁殑缁煎悎娴嬭瘯锛?/p>

<html>
<head>
<title>event test</title>
<script type="text/javascript">
function eventTest(){
alert("event.altKey   = " + event.altKey);
alert("event.ctrlKey  = " + event.ctrlKey);
alert("event.shiftKey = " + event.shiftKey);

alert("event.clientX = " + event.clientX);
alert("event.clientY = " + event.clientY);
alert("event.offsetX = " + event.offsetX);
alert("event.offsetY = " + event.offsetY);
alert("event.screenX = " + event.screenX);
alert("event.screenY = " + event.screenY);
alert("event.x       = " + event.x);
alert("event.y       = " + event.y);

alert("event.keyCode      = " + event.keyCode);
alert("event.srcElement   = " + event.srcElement);
alert("event.toElement    = " + event.toElement);
alert("event.fromElement  = " + event.fromElement);
alert("event.propertyName = " + event.propertyName);
alert("event.returnValue  = " + event.returnValue);
alert("event.srcFilter    = " + event.srcFilter);
alert("event.type         = " + event.type);
alert("event.cancelBubble = " + event.cancelBubble);
}
</script>
</head>

<body onmousedown="eventTest();">
</body>
</html>

鏈枃鍦板潃锛?a href="http://www.darkmi.com/blog/archives/1319" title="event瀵硅薄灏忕粨" rel="bookmark">event瀵硅薄灏忕粨

TAG鏍囩锛?a href="http://www.darkmi.com/blog/archives/tag/event" rel="tag">event

郑重声明:资讯 【event对象小结| darkmi'blog】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——