function addEvent(obj, type, fn) {
if (window.addEventListener) {//ie9+ chrome fireFox
obj.addEventListener(type, fn, false);
} else if (window.attachEvent) {//旧版本ie(edge不支持)
obj.attachEvent('on' + type, fn);
} else {
obj['on' + type] = fn;
}
}
function removeEvent(obj, type, fn) {
if (window.removeEventListener) {//ie9+ chrome fireFox
obj.removeEventListener(type, fn, false);
} else if (window.detachEvent) {//旧版本ie(edge不支持)
obj.detachEvent('on' + type, fn);
} else {
obj['on' + type] = null;
}
}
推荐文章