카운트 다운 js

Jop Tip 2010. 6. 3. 14:18

<html>
<head>
<title>카운트 다운</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<SCRIPT LANGUAGE="JavaScript">
<!--
function getTime() {
now = new Date();
later = new Date("JANUARY 01 2004 0:00:01"); //완료시간 지정 - 월 일 년 시 분 초
days = (later - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (later - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (later - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (later - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);

if (secondsRound <= 9) {
s1.innerHTML = "0";
s2.innerHTML = secondsRound;
} else {
s1.innerHTML = Math.floor(secondsRound/10);
s2.innerHTML = secondsRound%10;
}

if (minutesRound <= 9) {
m1.innerHTML = "0";
m2.innerHTML = minutesRound;
} else {
m1.innerHTML = Math.floor(minutesRound/10);
m2.innerHTML = minutesRound%10;
}

if (hoursRound <= 9) {
h1.innerHTML = "0";
h2.innerHTML = hoursRound;
} else {
h1.innerHTML = Math.floor(hoursRound/10);
h2.innerHTML = hoursRound%10;
}

if (daysRound <= 9) {
d1.innerHTML = "0";
d2.innerHTML = "0";
innerHTML = daysRound;
}

if (daysRound <= 99) {
d1.innerHTML = "0";
d2.innerHTML = Math.floor((daysRound/10)%10);
d3.innerHTML = Math.floor(daysRound%10);
}

if (daysRound <= 999) {
d1.innerHTML = Math.floor(daysRound/100);
d2.innerHTML = Math.floor((daysRound/10)%10);
d3.innerHTML = Math.floor(daysRound%10);
}
newtime = window.setTimeout("getTime();", 1000);
}
//-->
</script>
</head>


<BODY onLoad="getTime()">
*******************************

위에있는 소스 밑에 이 것을 쓰세요

********************************
<center>
<b>새해가 얼마나 남았나요?</b>

<br><br>

<font id="d1">0</font>
<font id="d2">0</font>
<font id="d3">0</font>일
<font id="h1">0</font>
<font id="h2">0</font>시간
<font id="m1">0</font>
<font id="m2">0</font>분
<font id="s1">0</font>
<font id="s2">0</font>초

</body>
</html>

------------------------------------------------------------
<script>
var minutes = 2; //몇 분
var seconds = 60; //몇 초?
function countdown() {
seconds--;
if(seconds == 0 && minutes == 0){
// newwin.close();
}else if(seconds == 0) {
minutes--;
seconds = 60;
}
var timeValue = "";// + ((hours >12) ? hours -12 :hours)
timeValue += ((minutes < 10) ? "0" : "") + minutes;
timeValue += ((seconds < 10) ? "분 0" : "분 ") + seconds+"초";
count.innerText = timeValue+" 완료";
if(!(seconds == 0 && minutes == 0)){
setTimeout("countdown()",1000);
}
}
//d0cument.write(""+min+"분 "+ cnt+"초후에 닫힙니다.");
d0cument.write("<div id='count'>&nbsp;</div>");
setTimeout("countdown()",1000);
</script>
Posted by omok
,