window.onload = function () {
var oButton = document.getElementById('button');
addEvent(oButton, 'click', fn1);
};
function fn1(e) {
alert('1');
};
function addEvent(obj, type, fn) {
if (typeof obj.addEventListener != 'undefined') {
obj.addEventListener(type, fn, false);
} else{
if(!obj.events) obj.events={};
if(!obj.events[type]){
obj.events[type] = [];
if(obj['on'+type]) obj.events[type][0] =fn; // ??问题在这里
}
obj.events[type][addEvent.ID++] = fn;
obj['on'+type]=function(){
for(var i in obj.events[type]){
obj.events[type][i]();
}
}
}
};
addEvent.ID=1;
为什么要做判断事件存不存在'这句话是不是多余。
相关分类