zoukankan      html  css  js  c++  java
  • JavaScript-跨浏览器事件处理程序(EventUtil)

    事件操作对象:

    var EventUtil= {

      //添加事件

      addHandler: function (element, type, handler) {
        if (element.addEventListener) {
          element.addEventListener(type, handler, false);
        }else if (element.attachEvent) {  //IE
          element.attachEvent("on" + type, handler, false);
        } else {
          element["on" + type] = handler;
        }
      },

      //移除对象
      removeHandler: function (element, type, handler) {
        if (element.removeEventListener) {
          element.removeEventListener(type, handler, false);
        } else if (element.detachEvent) {  //IE
          element.detachEvent("on" + type, handler, false);
        } else {
          element["on" + type] = null;
        }
       },

      //获取事件对象
      getEvent: function (event) {
        return event ? event : window.event;
      },

      //获取目标对象
      getTarget: function (event) {
        return event.target || event.srcElement;
      },

      //取消默认事件
      preventDefault: function (event) {
        if (event.preventDefault) {
          event.preventDefault();
        } else {  
          event.returnValue;
        }
      },

      //停止冒泡

      stopPropagation: function (event) {
        if (event.stopPropagation) {
          event.stopPropagation();
        } else {

          event.cancelBubble = true;
        }
      }
    };

  • 相关阅读:
    Linux 常用命令-01
    神经网络工具箱torch.nn -05
    Autograd与计算图-04
    Tensor的索引与变形-03
    Tensor数据类型-00
    Tensor的创建与维度查看-01
    转载:网友对rootfs的理解
    【转载】linux启动流程分析
    windows7 自带计算器bug
    网上同仁对linux文件系统的剖析
  • 原文地址:https://www.cnblogs.com/brandbao-blog/p/12235317.html
Copyright © 2011-2022 走看看