我在页面上放了三个DIV对像,我的意图是单击一个DIV对像,就在它的上面显示一个提示筐,几秒钟后自动消失.请问怎么实现,我只能做到,单击出现一个提示框框,但,自动消失不太会.就像QQ农场上的面的那种提示信息一样.

解决方案 »

  1.   

    可以用一个div模拟提示框
    这样就好做了。。
      

  2.   

    <!doctype html>
    <html>
    <head>
    <style>
    #demo {display:none;width:100px;height:50px;border:1px solid black;background:yellow;cursor:pointer;}
    #close {height:10px;font-size:10px;text-align:right;border-bottom:1px solid black;background:yellow;}
    .onc {background:red;width:200px;height:200px;margin-left:auto;margin-right:auto;margin-top:100px;}
    </style>
    <script type="text/javascript">
      var oC=0;
    window.onload=function() {
      var oDiv=document.getElementsByClassName("onc");
      var oClose=document.getElementById("close");
      oClose.onclick=function() {
        demo.style.display="none";
      };
      for(x in oDiv)
      {
        oDiv[x].onclick=function() {
      var oTop=this.offsetTop+100;
      var oLeft=this.offsetLeft+50;
      demo.style.position="fixed";
      demo.style.top=oTop+"px";
      demo.style.left=oLeft+"px";
      demo.style.display="block";
      oC=1;
      if(oC=1)
     {
       oC=0;
       setTimeout("demo.style.display='none';",1000);
     }
    };
      }
    };
    </script>
    </head>
    <body>
    <div id="demo">
    <div id="close">×
    </div>
    </div>
    <div class="onc"></div>
    </body>
    </html>
      

  3.   

    自动消失
    setTimeout(function(){
        //display:none
    }, time);