• Javascript 的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 及 IE 同时支持移除指定的事件, 用途是移除设定的事件, 格式分别如下:

    W3C格式:

    removeEventListener(event,function,capture/bubble);

    Windows IE的格式如下:

    detachEvent(event,function);

  • 相关阅读:
    第3次作业卷积神经网络
    SpringCloud Sidecar 整合.Net WebApi
    redefinition of class解决
    DP学习笔记
    NOIP2018 Day2毒瘤题目
    NOIP Day1总结
    关于DP
    这次的PION的总结
    NOIP模拟赛D2T1自己的解题思路
    ABAP Editor自动完成功能
  • 原文地址:https://www.cnblogs.com/Mygirl/p/2044512.html
Copyright © 2020-2023  润新知