JavaScript event兼容性


Event兼容性代码,按照W3C标准兼容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var fixEvent = function(e){
    e =  e || window.event;
    if(!e.preventDefault){
      e.preventDefault = function(){
        event.returnValue = false;
      };
    }
    if(!e.stopPropagation){
      e.stopPropagation = function(){
         event.cancelBubble = true;
      };
    }
    if(e.pageX === undefined && e.pageY === undefined){
      var doc =document.documentElement || document.body;
      e.pageX = e.clientX + doc.scrollLeft - doc.clientLeft;
      e.pageY = e.clientY + doc.scrollTop - doc.clientTop;
    }
    if(!e.target){
      e.target = e.srcElement;
    }
    return e;
  };

JavaScript event兼容性

上一篇:微信小程序基础 | 小程序事件的绑定 | 08


下一篇:使用u-view框架做小程序的弹窗效果