网上搜来的,看样子不错,记一笔。//------------------------------------
//heavilybasedontheQuirksmodeaddEventcontestwinner,JohnResig
//addEvent
functionaddEvent(obj,type,fn){
if(obj.addEventListener)obj.addEventListener(type,fn,false);
elseif(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
functionremoveEvent(obj,type,fn){
if(obj.removeEventListener)obj.removeEventListener(type,fn,false);
elseif(obj.detachEvent){
obj.detachEvent("on"+type,obj[type+fn]);
obj[type+fn]=null;
obj["e"+type+fn]=null;
}
}
【javascript add event remove event】相关文章:
★ JavaSacript中charCodeAt()方法的使用详解