javascript add event remove event
更新时间:2008年04月07日 20:21:40 作者:
javascript事件绑定和删除功能代码
网上搜来的,看样子不错,记一笔。//------------------------------------
// heavily based on the Quirksmode addEvent contest winner, John Resig
// addEvent
function addEvent(obj,type,fn){
if(obj.addEventListener) obj.addEventListener(type,fn,false);
else if(obj.attachEvent){
obj["e"+type+fn]=fn;
obj[type+fn]=function(){obj["e"+type+fn](window.event);}
obj.attachEvent("on"+type,obj[type+fn]);
}
}
//------------------------------------
// removeEvent
function removeEvent(obj,type,fn){
if(obj.removeEventListener) obj.removeEventListener(type,fn,false);
else if(obj.detachEvent){
obj.detachEvent("on"+type,obj[type+fn]);
obj[type+fn]=null;
obj["e"+type+fn]=null;
}
}
// heavily based on the Quirksmode addEvent contest winner, John Resig
// addEvent
function addEvent(obj,type,fn){
if(obj.addEventListener) obj.addEventListener(type,fn,false);
else if(obj.attachEvent){
obj["e"+type+fn]=fn;
obj[type+fn]=function(){obj["e"+type+fn](window.event);}
obj.attachEvent("on"+type,obj[type+fn]);
}
}
//------------------------------------
// removeEvent
function removeEvent(obj,type,fn){
if(obj.removeEventListener) obj.removeEventListener(type,fn,false);
else if(obj.detachEvent){
obj.detachEvent("on"+type,obj[type+fn]);
obj[type+fn]=null;
obj["e"+type+fn]=null;
}
}
相关文章
手把手教你 CKEDITOR 4 实现Dialog 内嵌 IFrame操作详解
这篇文章主要介绍了手把手教你 CKEDITOR 4 实现Dialog 内嵌 IFrame操作,结合实例形式分析了CKEDitor4 Dialog内嵌IFrame具体操作步骤与相关注意事项,需要的朋友可以参考下2019-06-06
最新评论