都是mousedown + mouseup,drag中间多个mousemove,我想在drag的时候不要启动click时该执行的事件,或者执行了然后回滚回去,但是都没有找到很好的方法,总之就是要让drag的时候不产生click的效果,应该怎么做,代码有点多,这里帖不了,可以邮件联系,谢谢!

解决方案 »

  1.   

    看看是不是你要的效果
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>new page</title>
    <script>
    var x=0;
    var y=0;
    var can_move=false;
    var isclick=true;
    function mouse_down(){
    x=event.x;
    y=event.y;
    can_move=true;
    }
    function mouse_move(){
    if(can_move){
    var top=document.all.div1.style.top;
    var left=document.all.div1.style.left;
    document.all.div1.style.top=parseInt(top.substring(0,top.length-2))+(event.y-y);
    document.all.div1.style.left=parseInt(left.substring(0,left.length-2))+(event.x-x);
    y=event.y;
    x=event.x;
    isclick=false;
    div1.innerHTML="drag";
    }
    }
    function mouse_up(){
    can_move=false;
    }
    function mouse_click(){
    if(isclick){
    div1.innerHTML="click";
    }else{
    isclick=true;
    }}
    document.onmousemove=mouse_move;
    </script>
    </head>
    <body>
    <div id=div1 onmousedown='mouse_down()' onclick="mouse_click()" onmouseup='mouse_up()' style='position:absolute;top:100px;left:100px;width:100px;height:100px;background-color:#cccccc'></div>
    </body>
    </html>
      

  2.   

    感觉好像挂了onclick事件之后drag事件就没用了...