标签:
1.事件绑定,删除,传播,默认方式,获取类型的兼容
var eventList = { //添加事件兼容 addEvent:function (event,type,backevent) { if (event.addEventListener) { event.addEventListener(type,backevent,false);//false为冒泡true为捕获 } else if(event.attachEvent){ event.attachEvent(‘on‘+type,backevent); }else{ event[‘on‘+type] = backevent; }; }, //删除事件兼容 removeEvent:function (event,type,backevent) { if (event.removeEventListener) { event.removeEventListener(type,backevent,null); } else if(event.detachEvent){ event.detachEvent(‘on‘+type,backevent); }else{ event[‘on‘+type]=null; }; }, //阻止冒泡向上传播 stopPro:function (event) { if (event.stopPropagation) { event.stopPropagation(); } else{ event.cancelBubble = true; }; }, //阻止默认事件 stopDefault:function (event) { if (event.preventDefault) { event.preventDefault(); } else{ event.returnValue = false; }; }, //获取事件类型 getType:function (event) { return event.type; }, //获取事件 getEvent:function (event) { return event?event:window.event; }, //获取事件目标 getElement:function (event) { return event.target||event.srcElement; } }
标签:
原文地址:http://www.cnblogs.com/fang8580/p/3553981.html