为了账号安全,请及时绑定邮箱和手机立即绑定

DOM2事件添加再删除怎么行不通呀,DOM0就行?

DOM2事件添加再删除怎么行不通呀,DOM0就行?

慕粉4076523 2016-12-25 14:20:53
     // 添加事件监听      function addEvent(ele,type,handler){       if(ele.addEventListener){console.log('1')         ele.addEventListener(type,handler,false);       }       else if(ele.attachEvent){console.log('2')         ele.attachEvent('on'+type,handler);       }else{console.log('3')         ele['on'+type]=handler;       }     }     // 删除事件监听     function removeEvent(ele,type,handler){       if(ele.removeEventListener){console.log('-1')         ele.removeEventListener(type,handler,false);       }       else if(ele.detachEvent){console.log('-2')         ele.detachEvent('on'+type,handler);       }else{console.log('-3')         ele['on'+type]=handler;       }     }      //DOM2级添加事件       addEvent(drag,'mousedown',function(){         xPanel=event.clientX-panel.offsetLeft;         yPanel=event.clientY-panel.offsetTop;         addEvent(document,'mousemove',function(event){         dragPanel(event,xPanel,yPanel);         })         addEvent(document,'mouseup',function(){           removeEvent(document,'mousemove',null);           removeEvent(document,'mouseup',null);         }) })//DOM0级的    function dragDown(){       xPanel=event.clientX-panel.offsetLeft;       yPanel=event.clientY-panel.offsetTop;       document.onmousemove=function(event){         dragPanel(event,xPanel,yPanel);       }       // 释放鼠标       document.onmouseup=function(){         document.onmousemove=null;         document.onmouseup=null;       }     }
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1385 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信