Formatting the event object

尽量将IE与DOM函数事件对象不同的性质或方法转成DOM标准
 

EventUtil.formatEvent = function (oEvent) {

   if (isIE && isWin) {                                          //判断IE的方法略
       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;
};

posted on 2016-01-26 11:16  迷茫小飞侠  阅读(124)  评论(0编辑  收藏  举报

导航