我这里有个table表格,我想在mouse移动到表格项的时候弹出一个菜单,但是为了避免弹出的太快影响到server。 我想延时两秒,做法如下
//for popup windowvar popup_timeout = null;
function popup_mouse_over(event){
    clearTimeout(popup_timeout);     popup_timeout = setTimeout(function(){showInfoBox(event);},2000); 
}function popup_mouse_out(event){    clearTimeout(popup_timeout); 
}
这两个函数分别赋给对应的 onmouseover和onmouseout, 在没加这个延时的时候一切工作正常, 加了之后,就告诉我
event对象不存在。 btw:我要在showinfoBox里用event来定位弹出菜单的位置。。请问该怎么做,谢谢

解决方案 »

  1.   

    popup_timeout = setTimeout(function(){showInfoBox(event);},2000);   改为
    popup_timeout = setTimeout(function(e){showInfoBox(e);}(event),2000);  试试 
      

  2.   


    var popup_timeout = null;
    function popup_mouse_over(event){
      clearTimeout(popup_timeout);  
      popup_timeout = setTimeout((
         function(obj){
            return function(){
                showInfoBox(obj);
            }
         }
      )(event),2000);  
    }function popup_mouse_out(event)
    {
      clearTimeout(popup_timeout);  
    }
      

  3.   

    function popup_mouse_over(event){
      clearTimeout(popup_timeout); 
      function test(){
         (function tt(e){
            showInfoBox(e);
         })(event)
      }
      popup_timeout = setTimeout(test,2000); 
    }
    现在应该可以了
      

  4.   

    发错了,改成下面这样:
    function popup_mouse_over(event){
      clearTimeout(popup_timeout); 
      function test(){
      (function(e){
         showInfoBox(e);
      })(event)
      }
      popup_timeout = setTimeout(test,2000); 
    }
      

  5.   


    谢谢,这个方法在firefox下可以用,但是ie6里用不成阿
      

  6.   

    我发现在ie6里面那个event参数始终是null, 着该咋办呢
      

  7.   

    在浏览器中一般event的参数,默认的都有值,你再引用的话会冲突,才会null的,用别的参数来代替event
      

  8.   

    饿,没注意这个问题。解决办法如10楼,将上面函数改成下面这样:
    function popup_mouse_over(mse){
      clearTimeout(popup_timeout); 
      function test(){
      (function(e){
      showInfoBox(e);
      })(mse)
      }
      popup_timeout = setTimeout(test,2000); 
    }
      

  9.   

    晕了。。还是未定义,这次连firefox都不行了。。我用了个很猥琐的方法搞好了。。定义了一个全局变量,然后把event里我需要的属性赋给它。。然后用这个全局变量做参数传递。。太猥琐了。。唉。。凑合用吧谢谢各位
      

  10.   

    很奇怪,我写的测试程序,在ie,firefox下均可。如下:
    <!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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
    function func1(mse){
        function func2(){
           (function(e){
               tt(e);
           })(mse)
        }
        setTimeout(func2,2000);
    }
    function tt(e){
       alert(e);
    }
    </script>
    </head><body>
    <input type="button" value="Display timed alertbox!" onClick="func1(event)">
    </body>
    </html>
      

  11.   

    另外,发现func1(mse)中的参数为event也可。
      

  12.   

    是ie 6吗? 可能我这里环境特殊, 我是在linux下面用firefox,  虚拟机里用ie6..javascript太让我头大了