IE于FF事件分派和触发

FF下事件分派和触发:

//绑定
window.addEventListener("mousewheel",function(event){
  alert(event.type)
  alert(event.clientX)
},false);

var event = document.createEvent("MouseEvent");
event.initMouseEvent("mousewheel",true,null,window,0,0,0,1,0,false,false,false,false,0,null);
window.dispatchEvent(event)

IE下事件的分派和触发:

//绑定
document.attachEvent("onmousewheel",function(){
      var e = window.event;
      alert(e.aa)
});

var event = document.createEventObject();
event.log = "test"
document.fireEvent("onmousewheel",event)

FF只能实现事件分派,不能实现手动触发。如果非原浏览器原生支持的事件类型,addEventListener是一概不理会.

IE简单得多了,没有初始化事件步骤,无法设置其属性,但可设置自定义属性。

参考:http://www.cnblogs.com/rubylouvre/archive/2010/05/01/1725462.html

你可能感兴趣的:(JavaScript,html,浏览器,IE)