![](/img/trans.png)
[英]Reveal div if no click on a certain other div for more than x seconds
[英]Reveal a div after x seconds, and reveal another div after y seconds
我對此很陌生,但我嘗試在1秒后顯示div1,並在5秒后顯示div2。 目前,僅div2在1秒后顯示。 請幫助我修復JavaScript。
我還想知道在顯示div2之后如何隱藏div1。
我的代碼:
<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>
您不能有兩個具有相同名稱的功能。 將第二部分更改為
function showIt2() {
document.getElementById("div2").style.visibility = "visible";
}
setTimeout("showIt2()", 5000); // after 5 secs
演示: http : //jsfiddle.net/W9YU5/
兩個問題。
setTimeout(showIt, 5000); // after 5 secs
setTimeout(showIt, 5000); // after 5 secs
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.