第一种写法
document.getElementById('xx').onmousedown = function(){
   document.onmousemove = function(){
       
   }
}第二种写法
document.getElementById('xx').onmousedown = function(){
   
}
document.getElementById('xx').onmousemove = function(){
       
}请问这两个不仅从写法不一样,他的表达意思一样吗???

解决方案 »

  1.   

    第一种,如果没有触发过mousedown事件的时候mousemove将不会被触发.第二种, mousedown不管触发没有, mousemove 都会触发.
      

  2.   

    第一种写法
    document.getElementById('xx').onmousedown = function(){
      document.onmousemove = function(){    
      }
    }第二种写法
    document.getElementById('xx').onmousedown = function(){
      document.getElementById('xx').onmousemove = function(){   
      }
    }请问这两种写法最终实现的效果一样吗?
      

  3.   

    汗. 没看到. 第一种触发鼠标在document上面移动的事件.
      

  4.   

    第一种写法
    document.getElementById('xx').onmousedown = function(){
     [color=#FF0000] [color=#FF0000]document.onmousemove = function(){ ---> 这样写跟地下有什么区别[/color]  }[/color]
    }第二种写法
    document.getElementById('xx').onmousedown = function(){
      document.getElementById('xx').onmousemove = function(){   
      }
    --->跟上面有上面区别
    }请大家能够就说的详细一点吗?
      

  5.   

    第一种写法
    document.getElementById('xx').onmousedown = function(){
     document.onmousemove = function(){ ---> 这样写跟地下有什么区别 
    }第二种写法
    document.getElementById('xx').onmousedown = function(){
      document.getElementById('xx').onmousemove = function(){ 
    }--->跟上面有上面区别

    }请大家能够就说的详细一点吗?
      

  6.   

    这个很清楚呀,一个是在整个document上触发mouseover,一个是在xx元素上触发
      

  7.   

    我做一个鼠标拖动效果
    第一种写法,快速去拖动一个对象,对象始终跟随鼠标,不存在脱离
    document.getElementById('xx').onmousedown = function(){
     document.onmousemove = function(){ ---> 这样写跟地下有什么区别  
     }
    }第二种写法,也能拖动对象,但是必需慢慢拖动,快速去拖动一个对象,对象马上跟鼠标脱离
    document.getElementById('xx').onmousedown = function(){
    document.getElementById('xx').onmousemove = function(){ 
    }--->跟上面有上面区别
    }第三种写法,也能拖动对象,但是必需慢慢拖动,快速去拖动一个对象,对象马上跟鼠标脱离
    document.getElementById('xx').onmousedown = function(){
    }
    document.getElementById('xx').onmousemove = function(){ 
    }--->跟上面有上面区别
    请大家能够就说的详细一点吗?
      

  8.   

    第三种写法和第二种不是一样吗你快速拖动鼠标,对象和鼠标脱离,是因为你快速移动鼠标以后,对象的位置还没有移动到鼠标下,所以
    mousemove事件不会触发。(mousemove事件触发的条件是,鼠标在对象上,并且有移动。注:这里先不考虑事件冒泡)所以针对这个问题 才有了你写的第一种方案,即在document上注册mousemove事件,因为mousemove事件触发的条件都具备。
      

  9.   

    默认div_2.style.left=200px;
    第一种写法弹出200
    var moveLeft = parseInt(div_2.style.left);
    var moveTop = parseInt(div_2.style.top);
    title1_tr.onmousedown = function(evt){
          alert(moveLeft);
    }
    document.onmousemove=function(evt){
         var evt = evt ? evt  : window.event;
          var left =  evt.clientX; 
          div_2.style.left = left+'px';
    }第二种写法弹出500(假设对象被移动后的left=500)
    var moveLeft = 0;
    var moveTop = 0;
    title1_tr.onmousedown = function(evt){
          moveLeft = parseInt(div_2.style.left);
          moveTop = parseInt(div_2.style.top);
          alert(moveLeft);
    }
    document.onmousemove=function(evt){
         var evt = evt ? evt  : window.event;
          var left =  evt.clientX; 
          div_2.style.left = left+'px';
    }
    两种写法弹出值为什么不一样?
    像第二种写法,把moveLeft = parseInt(div_2.style.left);
    放在onmousedown事件里面,弹出500(对象移动之后)!
    假如在第二种写法的时候,把moveLeft = parseInt(div_2.style.left);放在onmousedown事件之外,跟第一种写法差不多,那么弹出值还是等于默认值200,这是为什么???
      

  10.   

    默认div_2.style.left=200px;
    第一种写法弹出200
    var moveLeft = parseInt(div_2.style.left);
    var moveTop = parseInt(div_2.style.top);
    title1_tr.onmousedown = function(evt){
      alert(moveLeft);
    }
    document.onmousemove=function(evt){
      var evt = evt ? evt : window.event;
      var left = evt.clientX;  
      div_2.style.left = left+'px';
    }第二种写法弹出500(假设对象被移动后的left=500)
    var moveLeft = 0;
    title1_tr.onmousedown = function(evt){
      moveLeft = parseInt(div_2.style.left);
      alert(moveLeft);

    }
    document.onmousemove=function(evt){
      var evt = evt ? evt : window.event;
      var left = evt.clientX;  
      div_2.style.left = left+'px';
    }
    两种写法弹出值为什么不一样?
    像第二种写法,把moveLeft = parseInt(div_2.style.left);
    放在onmousedown事件里面,弹出500(对象移动之后)!
    假如在第二种写法的时候,把moveLeft = parseInt(div_2.style.left);放在onmousedown事件之外,跟第一种写法差不多,那么弹出值还是等于默认值200,这是为什么???