单次事件绑定
/*
*element:所要侦听事件的标签
*eventType:事件类型
*handler:所要执行的操作
*/
functionsingleEvent(element,eventType,handler){//单次侦听时间,侦听后马上移除事件
if(element.addEventListener){//IE9+,opera,chrome,firefox,safari
element.addEventListener(eventType,handler,false);
element.addEventListener(eventType,function(){//移除绑定事件,注意顺序
element.removeEventListener(eventType,handler,false);
},false);
}elseif(element.attachEvent){//IE,opera
element.attachEvent("on"+eventType,function(){
element.detachEvent("on"+eventType,handler);//移除绑定事件,注意顺序
});
element.attachEvent("on"+eventType,handler);
}
}
相关推荐
Kakoola 2020-08-01
bearhoopIT之道 2020-08-16
凯哥Java 2020-07-04
haidaoxianzi 2020-07-04
delmarks 2020-06-28
aNian 2020-06-16
qingjiuquan 2020-06-07
fraternityjava 2020-06-04
明瞳 2020-06-04
HappyHeng 2020-05-28
88473166 2020-05-14
zkwgpp 2020-05-07
oXiaoChong 2020-05-07
ChainDestiny 2020-05-07
doomvsjing 2020-05-07
xuMelon 2020-05-04
MrLiar 2020-04-27