在x秒后显示div,并在y秒后显示另一个div [英] Reveal a div after x seconds, and reveal another div after y seconds

查看:152
本文介绍了在x秒后显示div,并在y秒后显示另一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此很新,但我试图在1秒后显示div1,并在5秒后显示div2。目前,只有div2在1秒后显示。请帮我修复javascript。

I am very new to this, but I'm attempting to reveal div1 after 1 second, and reveal div2 after 5 seconds. At the moment, only div2 is displaying after 1 second. Please help me fix the javascript.

我也想知道如何在显示div2后隐藏div1。

I'd also like to know how to hide div1 after div2 is displayed.

我的代码:

My code:

<div id="div1" style="visibility: hidden">Reveal Div 1 after 1 second</div>
<div id="div2" style="visibility: hidden">Reveal Div 2 after 5 seconds</div>

<script type="text/javascript">
function showIt() {
  document.getElementById("div1").style.visibility = "visible";
}
setTimeout("showIt()", 1000); // after 1 sec

function showIt() {
  document.getElementById("div2").style.visibility = "visible";
}
setTimeout("showIt()", 5000); // after 5 secs
</script>


推荐答案

你不能有2个同名的函数。将第二部分更改为

You cannot have 2 function with the same name. Change second part to

function showIt2() {
  document.getElementById("div2").style.visibility = "visible";
}
setTimeout("showIt2()", 5000); // after 5 secs

演示: http://jsfiddle.net/W9YU5/

这篇关于在x秒后显示div,并在y秒后显示另一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆