页面代码如下:
<div id='a'>AAA</div>
<div id='b'>BBB</div>
<div id='c'>CCC</div>
<div id='d'>DDD</div>
要求:
当鼠标放在某个div上3秒不移出,则弹出一个提示框,把div里的内容提示出来,
如果鼠标划过一个div或在div上停留的时间没有3秒则不弹出对话框提示。
知道的大家互相学习下,要详细点,请不要只说简单的几个字,谢谢!

解决方案 »

  1.   

    jq有事件延迟的。主要靠clearTimeout,setTimeout实现
      

  2.   

    这是我收藏的一个例子, 你试试<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
    <HTML>  
     <HEAD>  
      <TITLE> New Document </TITLE>  
    <SCRIPT LANGUAGE="JavaScript">  
    <!--   
        window.onload=function(){   
            var timer,div1=document.getElementById("show");   
            div1.onmouseover=function(){   
                timer=setTimeout(function(){document.getElementById("content").style.display='block'},3000);   
            }   
            div1.onmouseout=function(){   
                clearTimeout(timer);   
                document.getElementById("content").style.display='none';   
            }   
        }   
    //-->  
    </SCRIPT>  
     </HEAD>  
     <BODY>  
      <div id="show" style="width:100px;height:50px;border:1px solid gray">  
        <div id="content" style="display:none">显示内容</div>  
      </div>  
     </BODY>  
    </HTML>  
      

  3.   

    用两个函数控制鼠标移到和移出DIV的事件,移到时用setTimeout延时3秒执行你要执行的函数,如果提早移出就把延时取消<html>
    <head>
    <style type="text/css">
    <!--
    #a { position:absolute; width:200px; height:100px; top:0px; left:0px;  background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
    #b{ position:absolute; width:200px; height:100px; top:100px; left:0px;  background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
    #c{ position:absolute; width:200px; height:100px; top:200px; left:0px;  background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
    #d { position:absolute; width:200px; height:100px; top:300px; left:0px;  background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
    -->
    </style>
    </head>
    <body>
    <div id="a" onmouseout="func_mout();" onmouseover="func_mover();">AAA</div>
    <div id="b" onmouseout="func_mout();" onmouseover="func_mover();">BBB</div>
    <div id="c" onmouseout="func_mout();" onmouseover="func_mover();">CCC</div>
    <div id="d" onmouseout="func_mout();" onmouseover="func_mover();">DDD</div>
    <script>
    var t;
    function func_mover()
    {
    t = setTimeout("f()","3000");
    }
    function f()
    {
    alert("123");
    }
    function func_mout()
    {
    clearTimeout(t);
    }
    </script>
    </body>
    </html>
      

  4.   

    if(typeof(HTMLElement)!='undefined')  // 给非IE 浏览器添加方法 contains

        HTMLElement.prototype.contains = function(obj) 
        {   
          while(obj && obj.tagName)   
          { 
                if(obj == this) 
                  return true; 
                obj = obj.parentNode; 
          }    
                return false;   
        };   
    } var $ = function (id,obj) {  
        return 'string' == typeof(id) ? (obj||document).getElementById(id) : id;   
    }; 
    var timer;
    window.onload=function(){
    var div=$("div1");
    div.onmouseover=function(){var o=this;timer= setTimeout(function(){alert(o.innerHTML);},3000);};
    div.onmouseout=function(e){
                    e = e||event; 
                    e = e.toElement || e.relatedTarget ; // IE toElement  FF:relatedTarget
                   if(typeof(e)!="undefined" &&!this.contains(e)){clearInterval(timer);
    }
    };
      

  5.   

    鼠标移出时,要判断,目标控件是否当前控件的子控件,移到div 的子元素也会触发 div 的 onmouseout!
      

  6.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
     </head> <body>
    <div id='a'>AAA</div>
    <div id='b'>BBB</div>
    <div id='c'>CCC</div>
    <div id='d'>DDD</div>
    <div id="tip" style="display:none;border:1px solid #ddd;padding:10px;"></div>
    <script type="text/javascript">
    <!--
    function $(id){return document.getElementById(id)};
    (function(){
    var timer = null,tip = $('tip');
    for(var i=0;i<arguments.length;i++){
    var el = $(arguments[i]);
    el.onmouseover = function(){
    clearTimeout(timer);
    var _this = this;
    timer = setTimeout(function(){
    tip.style.display = 'block';
    tip.innerHTML = _this.innerHTML;
    },3000);
    }
    }
    tip.onmouseout = function(){this.style.display = 'none';}
    })('a','b','c','d');
    //-->
    </script>
     </body>
    </html>