为什么删除function()没作用???问题在文中最后面有注释的地方,求解!
var eventUtil = {
//添加句柄
addHandler:function(element, type, handler) {
if(element.addEventListener) {
element.addEventListener(type, handler, false); //如果支持DOM2级
}
else if(element.attachEvent) {
element.attachEvent('on'+type, handler); //支持IE
}
else {
element['on'+type] = handler; //DOM0级
}
},
//删除句柄
removeHandler:function(element, type, handler) {
if(element.removeEventListener) {
element.removeEventListener(type, handler, false);
}
else if(element.detachEvent) {
element.detachEvent('on'+type, handler);
}
else {
element['on'+type] = null;
}
}
}
//调用封装好的对象
eventUtil.addHandler(btn1, 'click', showMe);
eventUtil.removeHandler(btn1, 'click', showMe);
eventUtil.addHandler(btn2, 'click', function(){alert('我是' + this.value)});
eventUtil.removeHandler(btn2, 'click', function(){alert('我是' + this.value)});//这个没反应???