一直想在首页上添加一个北京奥运的倒计时器,在网上找了两个,一个不适合自己,另一个似乎不能用,于是自己动手修改了一下代码,发现效果还可以,代码如下:
原来的代码还是有点问题,全部修改了一下,现在应该没问题了
[code]
<Script Language = "JavaScript">
function ShowTimes()
{
var AfterDate= new Date("August 8,2008 20:00:00") //此处设定倒计时的目标日期
var now = new Date();
var LeaveTime = AfterDate.getTime() – now.getTime();
var LeaveDays = Math.floor(LeaveTime/(1000*60*60*24));
var LeaveHours = Math.floor(LeaveTime/(1000*60*60)%24);
var LeaveMinutes = Math.floor(LeaveTime/(1000*60)%60);
var LeaveSeconds = Math.floor(LeaveTime/1000%60);
document.Time.DAYS.value = LeaveDays;
document.Time.HOUS.value = LeaveHours;
document.Time.MINS.value = LeaveMinutes;
document.Time.SECS.value = LeaveSeconds;
setTimeout( 'ShowTimes()',1000);
}
</SCRIPT>
<div align=center>
<form method="post" name="Time">
<input type=text name="DAYS" size="2">天
<input type=text name="HOUS" size="1">时
<input type=text name="MINS" size="1">分
<input type=text name="SECS" size="1">秒
</form>
</div>
<SCRIPT>
ShowTimes()
</SCRIPT>
[/code]