拖动无非就是控制三个事件:onmousedown onmousemove onmouseup 你可以在 onmousedown 事件里加一个延时器 setTimeout,让它在比如300毫秒之后才开始拖动。而在 onmouseup 事件里加一段代码取消这个延时处理。这样就可以给你 300 毫秒的时间,若是 onclick 就不会触发拖动,若确实是拖动则在 300 毫秒之后开始运行。

解决方案 »

  1.   

    在onmouseup 里判断有没有拖动过, 有就不换图片,没有就换图,表示只点击,不用onclick可能会更好
      

  2.   

    onmousemove=funciton(){
    //设一个标志拖动过了
    }
    onmouseout=funciton(){
    //检查标志是否触发过onmouseover事件(拖动过)
    有就不换图
    else
     换图//清除标志
    }
      

  3.   

    楼主跟说书一样的忽悠, 你要是搞一个 alert() 那是不行了, 触发什么事件?
      

  4.   

    ...最近看东西总是很粗心呀...<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>shawl.qiu template</title>
    <style type="text/css">
    /* <![CDATA[ */
    /* ]]> */
    </style>
    <script type="text/javascript">
    //<![CDATA[
    if (navigator.appName=="Microsoft Internet Explorer") {
    //最大化窗口
    self.moveTo(-5,-5)
    self.resizeTo(screen.availWidth +8,screen.availHeight+8)
    //这个脚本定义的宽度其实比原窗口还要大那么一点.
    }
    //]]>
    </script>
    <script type="text/javascript">
    //<![CDATA[
    //]]>
    </script>
    <script type="text/javascript">
    //<![CDATA[
    function fDragging(obj, e){
    if(!e) e=window.event;
    obj.style.position='relative';
    var x=parseInt(obj.offsetLeft);
    var y=parseInt(obj.offsetTop);

    var x_=e.clientX-x;
    var y_=e.clientY-y;

    if(document.addEventListener){
    document.addEventListener('mousemove', inFmove, true);
    document.addEventListener('mouseup', inFup, true);
    } else if(document.attachEvent){
    document.attachEvent('onmousemove', inFmove);
    document.attachEvent('onmouseup', inFup);
    }

    inFstop(e);
    inFabort(e)

    function inFmove(e){
    var evt;
    if(!e)e=window.event;

    obj.style.left=e.clientX-x_+'px';
    obj.style.top=e.clientY-y_+'px';

    inFstop(e);
    } // shawl.qiu script
    function inFup(e){
    var evt;
    if(!e)e=window.event;

    if(document.removeEventListener){
    document.removeEventListener('mousemove', inFmove, true);
    document.removeEventListener('mouseup', inFup, true);
    } else if(document.detachEvent){
    document.detachEvent('onmousemove', inFmove);
    document.detachEvent('onmouseup', inFup);
    }

    inFstop(e);
    } // shawl.qiu script function inFstop(e){
    if(e.stopPropagation) return e.stopPropagation();
    else return e.cancelBubble=true;
    } // shawl.qiu script
    function inFabort(e){
    if(e.preventDefault) return e.preventDefault();
    else return e.returnValue=false;
    } // shawl.qiu script
    }
    //]]>
    </script>
    </head>
    <body><br />
    <br />
    <img src="images/01.jpg" width="400" height="381" 
    onclick="defaultStatus='just a test'; return true;" 
    onmousedown="fDragging(this, event)" />
    </body>
    </html>