在index.jsp页面中有一个button和一个div,当鼠标悬停在button区域内1秒,div显示,否则div不显示,同样,当鼠标离开button区域1秒后,div消失,否则依然显示,这样做也是为了防止用户用鼠标在button区域内随便乱晃动,而造成的无效操作。请各位大侠能给我一点建议,谢谢!

解决方案 »

  1.   

    必须要1秒后才消失吗? 如果我瞬间移进,然后又瞬间移出,这个过程没有到一秒这个DIV是消失 还是显示呢?
      

  2.   


    <!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>
    <script language='javascript' src='http://code.jquery.com/jquery-1.4.2.min.js'></script>
    <script language='javascript' type='text/javascript'>
    var flag=false;
    $(document).ready(
        function()
        {

    $('#buttonID').mouseover(function(){
    flag=true;
    setTimeout('mousemove()',1000);
    })
    .mouseout(function(){
    flag=false;
    setTimeout('mousemove()',1000);
    });
        }
    );
    function mousemove(){
    if(flag)
    $('#DivID').show();
    else
    $('#DivID').hide();
    }
    </script>
    </head>
    <body>
    <input type='button' id="buttonID" value='我的区域'>
    <div id="DivID" style="border:1px solid red">我是Div</div>
    </body>
    </html>
      

  3.   

    可以用function testtimeout(){
    var timer = setTimeout("checktimeout()",10000); 
    }
    checktimeout=function(){ alert("你要执行的DIV效果方法可以写这里面!"); 
     

    function stoper() {
    clearTimeout(timer);
    testtimeout();
    }
    document.getElementById("button").onfocus()=stoper;//