어떻게 카운트 다운 타이머를 만드나요?카운트 다운 타이머?
사용자가 페이지를로드하면 시계가 아래로 카운트를 시작하고 시간이 지나면 브라우저가 새 페이지로 리디렉션됩니다.
발견 한 사실은 그렇게 유용하지 않았습니다. http://encosia.com/2007/07/25/display-data-updates-in-real-time-with-ajax/
어떻게 카운트 다운 타이머를 만드나요?카운트 다운 타이머?
사용자가 페이지를로드하면 시계가 아래로 카운트를 시작하고 시간이 지나면 브라우저가 새 페이지로 리디렉션됩니다.
발견 한 사실은 그렇게 유용하지 않았습니다. http://encosia.com/2007/07/25/display-data-updates-in-real-time-with-ajax/
이와 비슷한? 순수 자바 스크립트와
<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>
아마도 가장 쉬운 방법은 Timer class을 사용하는 것입니다.
이 스레드를 읽고 끝낼 수있는 많은 아름다운이
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
}
<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>
, 감사 – 001
처럼 할 수 ... 당신은 통과하고 싶지 않아 setTimeout에 대한 문자열. 대신에 익명 함수를 전달하십시오 : 'setTimeout (function() {countDown (count-1);}); –
@rob : RobFlaherty의 의견에 따라 답변을 수정 해보십시오. – ThiefMaster