标签:document lis cli else type nbsp rem attach mouse
var btn3 = document.getElementById("btn");
function event(){}
var eventUtil = {
//添加句柄
addHandler:function(element,type,handler){//element表示的是哪个元素,type表示的是事件类型(click,mouseover),handler表示的是处理的函数
if(element.addEventListener)//DOM2级处理函数
element.addEventListener(type,handler,false);
else if(element.attachEvent)//IE事件处理程序
element.attachEvent("on"+type,handler);//这里要变成onclick,所以要加on
else
element["on"+type] = handler;//一般事件处理函数
},
//删除句柄
removeHandler:function(element,type,handler){
if(element.removeEventListener)
element.removeEventListener(type,handler,false);
else if(element.detachEvent)
element.distachEvent("on"+type,handler);
else
element["on"+type] = handler;
}
},
eventUtil.addHandler(btn3,"click",event);
eventUtil.removeHandler(btn3,"click",event);
标签:document lis cli else type nbsp rem attach mouse
原文地址:http://www.cnblogs.com/fireporsche/p/6196004.html