1. 程式人生 > >工具函數

工具函數

and || element urn bubble detach ppr def class

var util = {
            addHandler:function(ele,type,handler){
                if(ele.attachEvent){
                    //IE
                    ele.attachEvent(‘on‘+type,handler)                    
                }else{
                    ele.addEventListener(type,handler,false)
                }
            },
            removeHandler:
function(ele,type,cb){ if(ele.detachEvent){ ele.detachEvent(‘on‘+type,cb) }else{ ele.removeEventListener(type,cb,false); } ele[‘on‘+type] = null;//防止內存泄漏 }, getEvent:function
(event){ return event?event:window.event; }, getTarget:function(event){ return event.target || event.srcElement; }, preventDefault:function (event){ if(event.preventDefault){ event.preventDefault(); }
else{ event.returnVauel=false; } }, stopPropagation:function (event){ if (event.stopPropagation){ event.stopPropagation(); }else{ event.cancleBubble=true; } } }   

工具函數