2010-05-14 8 views

답변

10

이와 비슷한? 순수 자바 스크립트와

<div id="countDiv"></div> 

    <script> 
    function countDown (count) { 
     if (count > 0) { 
     var d = document.getElementById("countDiv"); 
     d.innerHTML = count; 
     setTimeout (function() { countDown(count-1); }, 1000); 
     } 
     else 
     document.location = "someotherpage.html"; 
    } 
    countDown(5); 
    </script> 
+0

, 감사 – 001

+6

처럼 할 수 ... 당신은 통과하고 싶지 않아 setTimeout에 대한 문자열. 대신에 익명 함수를 전달하십시오 : 'setTimeout (function() {countDown (count-1);}); –

+0

@rob : RobFlaherty의 의견에 따라 답변을 수정 해보십시오. – ThiefMaster

0

아마도 가장 쉬운 방법은 Timer class을 사용하는 것입니다.

0

이 스레드를 읽고 끝낼 수있는 많은 아름다운이

window.onload=function(){ // makes sure the dom is ready 
    setTimeout('function(){document.location = "http://www.google.com"}', 10000) // redirects you to google after 10 seconds 
} 
0
<p> 
    When this counter reaches 0, you will be redirected to 
    <a href="http://path.to.wherever/" id="redirectme">wherever</a>. 
    <span id="counter">10</span> 
</p> 
<script type="text/javascript"> 
(function(){ 

    var 
     counter = document.getElementById("counter"), 
     count = parseInt(counter.innerHTML), 
     url = document.getElementById("redirectme").href, 
     timer; 

    function countdown() { 
     count -= 1; 
     counter.innerHTML = count; 
     if (count <= 0) { 
      clearTimeout(timer); 
      window.location.assign(url); 
     } 
    } 

    timer = setInterval(countdown, 1000); // 1000 ms 

})(); 
</script>