var EventUtil = {
// oElement触发元素。sEvent绑定事件click?或者其他。fnHandler,绑定的函数。
addHandler: function (oElement, sEvent, fnHandler) {
oElement.addEventListener ? oElement.addEventListener(sEvent, fnHandler, false) : oElement.attachEvent("on" + sEvent, fnHandler)
},
removeHandler: function (oElement, sEvent, fnHandler) {
oElement.removeEventListener ? oElement.removeEventListener(sEvent, fnHandler, false) : oElement.detachEvent("on" + sEvent, fnHandler)
},
addLoadHandler: function (fnHandler) {
this.addHandler(window, "load", fnHandler)
}
}
//例子:(注意绑定的函数不需要加括号)
//EventUtil.removeHandler(myDiv,‘click‘,eventA);
//function eventA(){alert(‘绑定了A事件‘);}
时间: 2024-10-26 19:27:08