对于事件的监听/解除事件工具类

时间:2022-06-30 04:34:17
/**
事件工具
 */
var EventUtil = {
	addHandler : function(element, type, handler) {
		if (element.addEventListener) {
			//for ie9+
			element.addEventListener(type, handler, false);
		} else if (element.attachEvent) {
			//for ie8-
			element.attachEvent("on" + type, handler);
		} else {
			element["on" + type] = handler;
		}
	},
	removeHandler : function(element, type, handler) {
		if (element.removeEventListener) {
			//for ie9+
			element.removeEventListener(type, handler, false);
		} else if (element.detachEvent) {
			//for ie8-
			element.detachEvent("on" + type, handler);
		} else {
			element["on" + type] = null;
		}
	}
};