十二、 滑鼠事件
1. 滑鼠事件屬性(Mouse Event Properties )
Q:哪些事件屬性我可以用來分析滑鼠事件。
A:Netscape Navigator 4和Internet Explorer 4(以及較新版本)支援相當少的事件屬性。其中一些在兩個瀏覽器上是一樣的(例如,event.screenX或者event.typ);不過,多數還是平台相關。移動或點擊滑鼠,下面的文字框會顯示你當前瀏覽器()的所有事件屬性:(譯者註:由於原文執行個體不能正確運行,這裡只貼出相關的JavaScript代碼)
ns4=(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>3) ? true:false;ie4=(navigator.appName!="Netscape" && parseInt(navigator.appVersion)>3) ? true:false;serialN=0;function handlerFoo(e) { if (parseInt(navigator.appVersion)>3) { evt = ns4 ? e:event; var str=''; for (var k in evt) {str+='event.'+k+'='+evt[k]+'/n'} if (''+evt.type==''+self.document.f1.s1.options[self.document.f1.s1.selectedIndex].value) self.document.f1.t1.value=str; if (''+evt.type==''+self.document.f2.s2.options[self.document.f2.s2.selectedIndex].value) self.document.f2.t2.value=str; self.status='Number of events handled: '+serialN; serialN++; } return true;}if (parseInt(navigator.appVersion)>3) { document.onmousedown=handlerFoo; document.onmouseup=handlerFoo; document.onmouseover=handlerFoo; document.onmouseout=handlerFoo; document.onmousemove=handlerFoo; document.onclick=handlerFoo; if (navigator.appName=="Netscape") { document.captureEvents( Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE | Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK ) }}