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

     // 添加事件监听
     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;
      }
    }


慕粉4076523
浏览 1390回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP