zoukankan      html  css  js  c++  java
  • ie和火狐事件addEventListener()及attachEvent()区别分析

    Mozilla中:

    addEventListener的使用方式:

      target.addEventListener(type, listener, useCapture);

    target: 文档节点、document、window 或 XMLHttpRequest。
    type: 字符串,事件名称,不含“on”,比如“click”、“mouseover”、“keydown”等。
    listener :实现了 EventListener 接口或者是 JavaScript 中的函数。
    useCapture :是否使用捕捉,一般用 false 。例如:document.getElementById("testText").addEventListener("keydown", function (event) { alert(event.keyCode); }, false);


    IE中:

      target.attachEvent(type, listener);
    target: 文档节点、document、window 或 XMLHttpRequest。
    type: 字符串,事件名称,含“on”,比如“onclick”、“onmouseover”、“onkeydown”等。
    listener :实现了 EventListener 接口或者是 JavaScript 中的函数。 例如:document.getElementById("txt").attachEvent("onclick",function(event){alert(event.keyCode);});


    W3C格式:

    removeEventListener(event,function,capture/bubble);

    Windows IE的格式如下:

    detachEvent(event,function);


      target.addEventListener(type, listener, useCapture);
    target 文档节点、document、window 或 XMLHttpRequest。
    type 字符串,事件名称,不含“on”,比如“click”、“mouseover”、“keydown”等。
    listener 实现了 EventListener 接口或者是 JavaScript 中的函数。
    useCapture 是否使用捕捉,看了后面的事件流一节后就明白了,一般用 false
    事件触发时,会将一个 Event 对象传递给事件处理程序,比如:
    document.getElementById("testText").addEventListener("keydown", function (event) { alert(event.keyCode); }, false);

  • 相关阅读:
    (原创)monitor H3C switch with cacti
    (原创)monitor Dell Powerconnec 6224 with cacti
    (转载)运行主机管理在openvswitch之上
    图片鼠标滑动实现替换
    分布式缓存(一)失效策略和缓存问题击穿,雪崩,穿透
    Spring 事务源码学习
    FactoryBean和BeanFactory
    Spring AOP 源码学习
    “两地三中心”和“双活”
    安装 geopandas 步骤
  • 原文地址:https://www.cnblogs.com/GerryOfZhong/p/5219639.html
Copyright © 2011-2022 走看看