码迷,mamicode.com
首页 > 其他好文 > 详细

模式-初始化分支

时间:2017-04-06 18:58:49      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:==   function   att   nbsp   app   rem   ddl   cti   null   

var MYAPP = {};
MYAPP.event = {
    addListener: null,
    removeListener: null
};

if (typeof window.addEventListener === ‘function‘) {
    MYAPP.event.addListener = function(el, type, fn) {
        el.addEventListener(type, fn, false);
    };
    MYAPP.event.removeListener = function(el, type, fn) {
        el.removeListener(type, fn, false);
    }
} else if (typeof window.attachEvent === ‘function‘) {
    MYAPP.event.addListener = function(el, type, fn) {
        el.attachEvent(‘on‘ + type, fn);
    };
    MYAPP.event.removeListener = function(el, type, fn) {
        el.detachEvent(‘on‘ + type, fn);
    };
} else {
    MYAPP.event.addListener = function(el, type, fn) {
        el[‘on‘ + type] = fn;
    };
    MYAPP.event.removeListener = function(el, type, fn) {
        el[‘on‘ + type] = null;
    };
};

模式-初始化分支

标签:==   function   att   nbsp   app   rem   ddl   cti   null   

原文地址:http://www.cnblogs.com/Alan2016/p/6674615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!