简体   繁体   English

Javascript隐藏div并通过简单的倒数显示另一个div

[英]Javascript hide div and show another div with simple countdown

is there any way to hide div show another div using javascript? 有没有办法隐藏div使用javascript显示另一个div?

<div class="div1">"here must show countdown 10 seconds"</div>
<div class="div2">"show this div after countdown"</div>

for example: when page loaded, div1 must display and it must have 10 seconds countdown. 例如:加载页面时,div1必须显示并且它必须具有10秒倒计时。 when countdown is done then hide div1 and show div2 倒数完成后,隐藏div1并显示div2

Thanks for who answer my question. 感谢您回答我的问题。

and Thanks for RTPMatt answered me once but it didn't work. 感谢RTPMatt回答了我一次,但是没有用。

You might try this : 您可以尝试这样:

$(function (){
 $("#div1").show();
 setTimeout(function(){$("#div1").hide(); $("#div2").show();},10*1000)
}) 

When dom is loaded , you show div1 . 加载dom后,显示div1 then you start a timer which when pulse , hides div1 and show div2 然后您启动一个计时器,该计时器在pulse时隐藏div1并显示div2

Please try this 请尝试这个

    <script language="javascript">
    var timeout,interval
    var threshold = 10000;
    var secondsleft=threshold;

    window.onload = function()
    {
        startschedule();
    }

     function startChecking()
     {
        secondsleft-=1000;
        document.querySelector(".div1").innerHTML = "Activating in " + Math.abs((secondsleft/1000))+" secs";  
        if(secondsleft == 0)
        {
            //document.getElementById("clickme").style.display="";
            clearInterval(interval);
            document.querySelector(".div1").style.display="none";
            document.querySelector(".div2").style.display="";
        }
    }
    function startschedule()
    {
          clearInterval(interval);
          secondsleft=threshold;
          document.querySelector(".div1").innerHTML = "Activating in " + Math.abs((secondsleft/1000))+" secs";  
           interval = setInterval(function()
           {
               startChecking();
           },1000)              
   }

   function resetTimer()
   {
        startschedule();
   }
</script>
    <div class="div1">"here must show countdown 10 seconds"</div>
    <div class="div2" style="display:none;">"show this div after countdown"</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM