首页 > 代码库 > 模式-初始化分支
模式-初始化分支
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;
};
};
模式-初始化分支