Forum de discussion
Forum « Programmation HTML » (archives)
Re: compteur (décompte de temps)
Envoyé: 27 septembre 2004, 9h48 par tigrou
<SCRIPT LANGUAGE="JavaScript">
<!--
var Now = new Date();
var EventDate1 = new Date("September 27, 2004 12:30:00");
var EventDate2 = new Date("September 27, 2004 12:32:00");
var EventDate3 = new Date("September 27, 2004 12:28:00");
if (Now > EventDate2)
{
var EventDate = EventDate1;
var EventName = "fin de la course 2004";
}
else if (Now > EventDate1)
{
var EventDate = EventDate2;
var EventName = "début des qualifs dans";
}
else
{
var EventDate = EventDate3;
var EventName = "fin des essais libres dans";
}
count=Math.floor((EventDate.getTime()-Now.getTime())/1000);
function toSt(n,cnt)
{
n=n.toString()
for (i=1;i=cnt-n.length;i++)
{
n=" "+n
}
return n
}
secCol="#000000";
function countdown()
{
d=new Date();
count=Math.floor((EventDate.getTime()-d.getTime())/1000);
if(count<=0)
{
document.timeForm.Input1.value = " 0"
document.timeForm.Input2.value = "days,"
document.timeForm.Input3.value = " 0"
document.timeForm.Input4.value = "hours, "
document.timeForm.Input5.value = " 0"
document.timeForm.Input6.value = "mins,"
document.timeForm.Input7.value = " 0"
document.timeForm.Input8.value = "secs."
return;
}
secs=toSt(count%60,2);
secStr = (secs == " 1") ? "sec." : "secs.";
count=Math.floor(count/60);
mins=toSt(count%60,2);
minStr = (mins == " 1") ? "min, " : "mins, ";
count=Math.floor(count/60);
hours=toSt(count%24,2);
hourStr = (hours == " 1") ? "hour, " : "hours, ";
count=Math.floor(count/24);
days=toSt(count,3);
dayStr = (days == " 1") ? "day, " : "days, "
document.timeForm.Input1.value = days
document.timeForm.Input2.value = dayStr
document.timeForm.Input3.value = hours
document.timeForm.Input4.value = hourStr
document.timeForm.Input5.value = mins
document.timeForm.Input6.value = minStr
document.timeForm.Input7.value = secs
if (navigator.appName=="Microsoft Internet Explorer")
{
if (secCol=="#FF0000")
{
secCol="#000000"
}
else
{
secCol="#FF0000"
}
document.timeForm.Input7.style.color = secCol
}
document.timeForm.Input8.value = secStr
setTimeout("countdown()",1000);
}
// -->
</SCRIPT>
<table border="0" align="center" width="169" cellpadding="0" cellspacing="0"><tr><td class="blockborder-topleft" width="1" height="25" nowrap></td><td width="167" height="25" align="center" valign="top" nowrap class="blockborder-top"><div style="color:#FFFFFF;margin:3px 0px 0px;"><b>Countdown to Next Race</b></div></td><td class="blockborder-topright" width="1" height="25" nowrap></td></tr><tr><td class="blockborder-left" width="1"></td><td bgcolor="#F8F8F8" nowrap>
<table border="0" width="100%" cellpadding="0" cellspacing="2"><tr><td>
<TABLE ALIGN='CENTER' BORDER='0' WIDTH='100%' HEIGHT='100%' CELLPADDING='0' CELLSPACING='0'>
<FORM NAME='timeForm'>
<TR>
<TD ALIGN='CENTER' VALIGN='TOP'>
<FONT COLOR='#000000'>
<SCRIPT language='JavaScript'>
<!--//
document.write(EventName);
//-->
</SCRIPT>
</FONT></TD>
</TR>
<TR>
<TD ALIGN='CENTER' VALIGN='TOP'> <FONT> <NOBR>
<INPUT CLASS='Time' SIZE='3' TYPE=text NAME=Input1>
<INPUT CLASS='Time' SIZE='4' TYPE=text NAME=Input2>
</NOBR> <NOBR>
<INPUT CLASS='Time' SIZE='2' TYPE=text NAME=Input3>
<INPUT CLASS='Time' SIZE='5' TYPE=text NAME=Input4>
</NOBR> <NOBR>
<INPUT CLASS='Time' SIZE='2' TYPE=text NAME=Input5>
<INPUT CLASS='Time' SIZE='5' TYPE=text NAME=Input6>
</NOBR> <NOBR>
<INPUT CLASS='Time' SIZE='2' TYPE=text NAME=Input7>
<INPUT CLASS='Time' SIZE='5' TYPE=text NAME=Input8>
</NOBR> <BR>
<img src="gr/images/feux_14.png" width="45" height="33">
<SCRIPT language='JavaScript'>
<!--//
countdown();
//-->
Réponses
|