现在的位置: 首页 > 综合 > 正文

JavaScript FAQ(十四)——鼠标事件(一)

2013年03月01日 ⁄ 综合 ⁄ 共 1223字 ⁄ 字号 评论关闭

十二、 鼠标事件

 

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
  )
 }
}

抱歉!评论已关闭.