首页 > 代码库 > 跨浏览器事件对象

跨浏览器事件对象

    var EventUtil = {        addHandler: function(elem,type,handler){            if (elem.addEventListener) {                    elem.addEventListener(type, handler, false);            }else if(elem.attachEvent){                    elem.attachEvent(‘on‘+type,handler);            }else{                    elem["on"+type] = handler;            }        },        removeHandler: function(elem,type,handler){            if (elem.removeEventListener) {                    elem.removeEventListener(type, handler, false);            }else if(elem.attachEvent){                    elem.detachEvent(‘on‘+type,handler);            }else{                    elem["on"+type] = handler;            }        },        getEvent: function(event){                return event ? event : window.event;        },        getTarget: function(event){                return event.target || event.srcElement;        },        preventDefault: function(e){                if ( e && e.preventDefault )                     e.preventDefault();                 else                     window.event.returnValue = http://www.mamicode.com/false; "iPhone版暂无下载,稍后推出,程序员正在拼命加班!");        EventUtil.preventDefault(e);});