zoukankan      html  css  js  c++  java
  • EventUtil.js

    var EventUtil = new Object;
    EventUtil.addEventHandler 
    = function (oTarget, sEventType, fnHandler) {
        
    if (oTarget.addEventListener) {
            oTarget.addEventListener(sEventType, fnHandler, 
    false);
        } 
    else if (oTarget.attachEvent) {
            oTarget.attachEvent(
    "on" + sEventType, fnHandler);
        } 
    else {
            oTarget[
    "on" + sEventType] = fnHandler;
        }
    };
            
    EventUtil.removeEventHandler 
    = function (oTarget, sEventType, fnHandler) {
        
    if (oTarget.removeEventListener) {
            oTarget.removeEventListener(sEventType, fnHandler, 
    false);
        } 
    else if (oTarget.detachEvent) {
            oTarget.detachEvent(
    "on" + sEventType, fnHandler);
        } 
    else { 
            oTarget[
    "on" + sEventType] = null;
        }
    };

    EventUtil.formatEvent 
    = function (oEvent) {
        
    if (isIE && isWin) {
            oEvent.charCode 
    = (oEvent.type == "keypress"? oEvent.keyCode : 0;
            oEvent.eventPhase 
    = 2;
            oEvent.isChar 
    = (oEvent.charCode > 0);
            oEvent.pageX 
    = oEvent.clientX + document.body.scrollLeft;
            oEvent.pageY 
    = oEvent.clientY + document.body.scrollTop;
            oEvent.preventDefault 
    = function () {
                
    this.returnValue = false;
            };

            
    if (oEvent.type == "mouseout") {
                oEvent.relatedTarget 
    = oEvent.toElement;
            } 
    else if (oEvent.type == "mouseover") {
                oEvent.relatedTarget 
    = oEvent.fromElement;
            }

            oEvent.stopPropagation 
    = function () {
                
    this.cancelBubble = true;
            };

            oEvent.target 
    = oEvent.srcElement;
            oEvent.time 
    = (new Date).getTime();
        }
        
    return oEvent;
    };

    EventUtil.getEvent 
    = function() {
        
    if (window.event) {
            
    return this.formatEvent(window.event);
        } 
    else {
            
    return EventUtil.getEvent.caller.arguments[0];
        }
    };
  • 相关阅读:
    A1035
    A1005
    A1073
    A1061
    A1058
    A1027
    A1019
    Java 操作临时文件创建与删除
    面试必会之HashMap源码分析
    springboot整合cxf框架启动报错
  • 原文地址:https://www.cnblogs.com/jackhuclan/p/1150097.html
Copyright © 2011-2022 走看看