event瀵硅薄姒傝堪
Javascript鐨凟vent瀵硅薄鐢ㄦ潵鎻忚堪Javascript鐨勪簨浠讹紝瀹冧富瑕佷綔鐢ㄤ簬IE4鍜孨N4浠ュ悗鐨勫悇涓祻瑙堝櫒鐗堟湰涓€?
Event浠h〃浜嬩欢鐘舵€侊紝濡備簨浠跺彂鐢熺殑鍏冪礌锛岄敭鐩樼姸鎬侊紝榧犳爣浣嶇疆鍜岄紶鏍囨寜閽姸鎬併€備竴鏃︿簨浠跺彂鐢?渚夸細鐢熸垚Event瀵硅薄锛屽鍗曞嚮涓€涓寜閽紝娴忚鍣ㄧ殑鍐呭瓨涓氨浜х敓鐩稿簲鐨?event瀵硅薄銆?
娉ㄦ剰锛?/strong> 涓嬮潰鐨勪緥瀛愬睍绀轰簡鍦ㄤ簨浠剁殑鏈彂鐢熺殑鏃跺€檈vent瀵硅薄骞朵笉瀛樺湪锛?/p>
绗竴涓猘lert涓簄ull锛岀浜屼釜alert涓衡€滄湭瀹氫箟鈥濄€?/p>
鍙湁鍦ㄤ簨浠剁殑鍙戠敓杩囩▼涓簨浠舵墠鏈夋晥锛?/p>
鍦ㄩ紶鏍囧崟鍑绘椂鏄剧ずevent浜嬩欢銆?/p>
event瀵硅薄鐨勫睘鎬?/strong>
锛?锛変笌浣嶇疆鐩稿叧鐨勫睘鎬э細 1. x 2. y 3.clientX 4.clientY 5.offsetX 6.offsetY 13.screenX 14.screenY 涓庡姛鑳介敭鏈夊叧鐨勫睘鎬э細 1.ctrlKey 2.altKey 3.shiftKey 鍏朵粬灞炴€э細 1.button 2.srcElement 3.toElement 4.fromElement 5.keyCode 6.srcFilter 7.cancelBubble 8.propertyName 9.returnValue 10.type 涓€涓簨浠剁殑缁煎悎娴嬭瘯锛?/p>
鏈枃鍦板潃锛?a href="http://www.darkmi.com/blog/archives/1319" title="event瀵硅薄灏忕粨" rel="bookmark">event瀵硅薄灏忕粨
锛?锛塭vent浠h〃浜嬩欢鐨勭姸鎬侊紝渚嬪瑙﹀彂event瀵硅薄鐨勫厓绱犮€侀紶鏍囩殑浣嶇疆鍙婄姸鎬併€佹寜涓嬬殑閿瓑绛夈€?br />
锛?锛塭vent瀵硅薄鍙湪浜嬩欢鍙戠敓鐨勮繃绋嬩腑鎵嶆湁鏁堛€?br />
锛?锛塭vent鐨勬煇浜涘睘鎬у彧瀵圭壒瀹氱殑浜嬩欢鏈夋剰涔夈€傛瘮濡傦紝fromElement 鍜?toElement 灞炴€у彧瀵?onmouseover 鍜?onmouseout 浜嬩欢鏈夋剰涔夈€?/p>
<head>
<title>event test</title>
<script type="text/javascript">
alert(window.event);
alert(Event);
</script>
</head>
<body>
</body>
</html>
x鈥?y锛宑lientX鈥?clientY鈥?offsetX鈥?offsetY鈥?screenX鈥?screenY鈥?/p>
鎻忚堪锛?br />
杩斿洖榧犳爣鐩稿浜巆ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌鐨剎杞村潗鏍囥€傚鏋滄病鏈塩ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌锛岄粯璁や互BODY鍏冪礌浣滀负鍙傝€冨璞°€?br />
璇硶锛?br />
event.x
娉ㄩ噴锛?br />
濡傛灉浜嬩欢瑙﹀彂鍚庯紝榧犳爣绉诲嚭绐楀彛澶栵紝鍒欒繑鍥炵殑鍊间负 -1
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>
鎻忚堪锛?br />
杩斿洖榧犳爣鐩稿浜巆ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌鐨剏杞村潗鏍囥€傚鏋滄病鏈塩ss灞炴€т腑鏈塸osition灞炴€х殑涓婄骇鍏冪礌锛岄粯璁や互BODY鍏冪礌浣滀负鍙傝€冨璞°€?br />
璇硶锛?br />
event.y
娉ㄩ噴锛?br />
濡傛灉浜嬩欢瑙﹀彂鍚庯紝榧犳爣绉诲嚭绐楀彛澶栵紝鍒欒繑鍥炵殑鍊间负 -1
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?
鎻忚堪锛?br />
杩斿洖榧犳爣鍦ㄧ獥鍙e鎴峰尯鍩熶腑鐨刋鍧愭爣銆?br />
璇硶锛?br />
event.clientX
娉ㄩ噴锛?br />
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>
鎻忚堪锛?br />
杩斿洖榧犳爣鍦ㄧ獥鍙e鎴峰尯鍩熶腑鐨刌鍧愭爣銆?br />
璇硶锛?br />
event.clientY
娉ㄩ噴锛?br />
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>
鎻忚堪锛?br />
妫€鏌ョ浉瀵逛簬瑙﹀彂浜嬩欢鐨勫璞★紝榧犳爣浣嶇疆鐨勬按骞冲潗鏍?br />
璇硶锛?br />
event.offsetX
鎻忚堪锛?br />
妫€鏌ョ浉瀵逛簬瑙﹀彂浜嬩欢鐨勫璞★紝榧犳爣浣嶇疆鐨勫瀭鐩村潗鏍?br />
璇硶锛?br />
event.offsetY
鎻忚堪锛?br />
妫€娴嬮紶鏍囩浉瀵逛簬鐢ㄦ埛灞忓箷鐨勬按骞充綅缃?br />
璇硶锛?br />
event.screenX
娉ㄩ噴锛?br />
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>
鎻忚堪锛?br />
妫€娴嬮紶鏍囩浉瀵逛簬鐢ㄦ埛灞忓箷鐨勫瀭鐩翠綅缃?br />
璇硶锛?br />
event.screenY
娉ㄩ噴锛?br />
杩欐槸涓彧璇诲睘鎬с€傝繖鎰忓懗鐫€锛屼綘鍙兘閫氳繃瀹冩潵寰楀埌榧犳爣鐨勫綋鍓嶄綅缃紝鍗翠笉鑳界敤瀹冩潵鏇存敼榧犳爣鐨勪綅缃€?/p>
ctrlKey鈥?shiftKey鈥?altKey鈥?
鎻忚堪锛?br />
妫€鏌trl閿殑鐘舵€併€?br />
璇硶锛?br />
event.ctrlKey
鍙兘鐨勫€硷細
褰揷trl閿寜涓嬫椂锛屽€间负 TRUE 锛屽惁鍒欎负 FALSE 銆傚彧璇汇€?/p>
鎻忚堪锛?br />
妫€鏌lt閿殑鐘舵€併€?br />
璇硶锛?br />
event.altKey
鍙兘鐨勫€硷細
褰揳lt閿寜涓嬫椂锛屽€间负 TRUE 锛屽惁鍒欎负 FALSE 銆傚彧璇汇€?/p>
鎻忚堪锛?br />
妫€鏌hift閿殑鐘舵€併€?br />
璇硶锛?br />
event.shiftKey
鍙兘鐨勫€硷細
褰搒hift閿寜涓嬫椂锛屽€间负 TRUE 锛屽惁鍒欎负 FALSE 銆傚彧璇汇€?/p>
button鈥?srcElement鈥?fromElement鈥?toElement鈥?keyCode鈥?br />
srcFilter鈥?cancelBubble鈥?propertyName鈥?returnValue鈥? type鈥?
鎻忚堪锛?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>
鎻忚堪锛?br />
杩斿洖瑙﹀彂浜嬩欢鐨勫厓绱犮€傚彧璇汇€?br />
璇硶锛?br />
event.srcElement
鎻忚堪锛?br />
妫€娴?onmouseover 鍜?onmouseout 浜嬩欢鍙戠敓鏃讹紝榧犳爣鎵€杩涘叆鐨勫厓绱犮€?鍙傝€冿細7.fromElement
璇硶锛?br />
event.toElement
娉ㄩ噴锛?br />
杩欐槸涓彧璇诲睘鎬с€?/p>
鎻忚堪锛?br />
妫€娴?onmouseover 鍜?onmouseout 浜嬩欢鍙戠敓鏃讹紝榧犳爣鎵€绂诲紑鐨勫厓绱犮€?鍙傝€冿細18.toElement
璇硶锛?br />
event.fromElement
娉ㄩ噴锛?br />
杩欐槸涓彧璇诲睘鎬с€?/p>
鎻忚堪锛?br />
妫€娴嬮敭鐩樹簨浠剁浉瀵瑰簲鐨勫唴鐮併€?br />
杩欎釜灞炴€х敤浜?onkeydown鈥?onkeyup鈥?鍜?onkeypress 浜嬩欢銆?br />
璇硶锛?br />
event.keyCode[ = keyCode]
鍙兘鐨勫€硷細
杩欐槸涓彲璇诲啓鐨勫€硷紝鍙互鏄换浣曚竴涓猆nicode閿洏鍐呯爜銆傚鏋滄病鏈夊紩鍙戦敭鐩樹簨浠讹紝鍒欒鍊间负 0 銆?/p>
鎻忚堪锛?br />
杩斿洖瑙﹀彂 onfilterchange 浜嬩欢鐨勬护闀溿€傚彧璇汇€?br />
璇硶锛?br />
event.srcFilter
鎻忚堪锛?br />
妫€娴嬫槸鍚︽帴鍙椾笂灞傚厓绱犵殑浜嬩欢鐨勬帶鍒躲€?br />
璇硶锛?br />
event.cancelBubble[ = cancelBubble]
鍙兘鐨勫€硷細
杩欐槸涓€涓彲璇诲啓鐨勫竷灏斿€?
TRUE 涓嶈涓婂眰鍘熺礌鐨勪簨浠舵帶鍒躲€?br />
FALSE 鍏佽琚笂灞傚厓绱犵殑浜嬩欢鎺у埗銆傝繖鏄粯璁ゅ€笺€?/p>
鎻忚堪锛?br />
璁剧疆鎴栬繑鍥炲厓绱犵殑鍙樺寲浜嗙殑灞炴€х殑鍚嶇О銆?br />
璇硶锛?br />
event.propertyName [ = sProperty ]
鍙兘鐨勫€硷細
sProperty 鏄竴涓瓧绗︿覆锛屾寚瀹氭垨杩斿洖瑙﹀彂浜嬩欢鐨勫厓绱犲湪浜嬩欢涓彉鍖栦簡鐨勫睘鎬х殑鍚嶇О銆?br />
杩欎釜灞炴€ф槸鍙鍐欑殑銆傛棤榛樿鍊笺€?br />
娉ㄩ噴锛?br />
浣犲彲浠ラ€氳繃浣跨敤 onpropertychange 浜嬩欢锛屽緱鍒?propertyName 鐨勫€笺€?/p>
鎻忚堪锛?br />
璁剧疆鎴栨鏌ヤ粠浜嬩欢涓繑鍥炵殑鍊?br />
璇硶锛?br />
event.returnValue[ = Boolean]
鍙兘鐨勫€硷細
true 浜嬩欢涓殑鍊艰杩斿洖
false 婧愬璞′笂浜嬩欢鐨勯粯璁ゆ搷浣滆鍙栨秷
渚嬪瓙瑙佹湰鏂囩殑寮€澶淬€?/p>
鎻忚堪锛?br />
杩斿洖浜嬩欢鍚嶃€?br />
璇硶锛?br />
event.type
娉ㄩ噴锛?br />
杩斿洖娌℃湁鈥渙n鈥濅綔涓哄墠缂€鐨勪簨浠跺悕锛屾瘮濡傦紝onclick浜嬩欢杩斿洖鐨則ype鏄痗lick
鍙銆?/p>
<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>
TAG鏍囩锛?a href="http://www.darkmi.com/blog/archives/tag/event" rel="tag">event