我正在制作一个竞赛平台..为此我需要一个倒数计时器..问题是我没有 JS..所以我用谷歌搜索并得到了这个计时器脚本..但它在网页中不起作用......请帮帮我.. 这是计时器的代码...我得到了 div 标签的框,但没有得到其中的计时器...请帮帮我,因为我是 JS 中的完整新手..
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>CoBo:Contest</title>
<link href="css/master.css" rel="stylesheet" type="text/css"/>
<script>
function start(myD, myH, myMins, mySecs, myL) {
var d = new Date();// Returns the Day (number) so we can set it to default
currentDay = d.getDate();
var month = 0;// '*' for next month, '0' for this month or 1 through 12 for the month
var day = myD;// Offset for day of month day or + day
var hour = myH;// 0 through 23 for the hours of the day
var minutes = myMins;// Minutes of the hour to End on
var seconds = mySecs;// Seconds of the minute to End on
var tz = - 7;// Offset for your timezone in hours from UTC
var lab = myL;// The id of the page entry where the timezone countdown is to show
displayTZCountDown(setTZCountDown(month, day, hour, minutes, seconds, tz), lab);
}
function setTZCountDown(month, day, hour, minutes, seconds, tz) {
var toDate = new Date();
if (month == '*')
toDate.setMonth(toDate.getMonth() + 1);
else if (month > 0) {
if (month <= toDate.getMonth())
toDate.setYear(toDate.getYear() + 1);
toDate.setMonth(month - 1);
}
if (day.substr(0, 1) == '+') {
var day1 = parseInt(day.substr(1));
toDate.setDate(toDate.getDate() + day1);
}
else {
toDate.setDate(day);
}
toDate.setHours(hour);
toDate.setMinutes(minutes - (tz * 60));
toDate.setSeconds(seconds);
var fromDate = new Date();
fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
var diffDate = new Date(0);
diffDate.setMilliseconds(toDate - fromDate);
return Math.floor(diffDate.valueOf() / 1000);
}
function displayTZCountDown(countdown, tzcd) {
if (countdown < 0)
document.getElementById(tzcd).innerHTML = "<b>Ended</b>";
else {
var secs = countdown % 60;
if (secs < 10)
secs = '0' + secs;
var countdown1 = (countdown - secs) / 60;
var mins = countdown1 % 60;
if (mins < 10)
mins = '0' + mins;
countdown1 = (countdown1 - mins) / 60;
var hours = countdown1 % 24;
var days = (countdown1 - hours) / 24;
if (hours < 10) {
var hours = "0" + hours;
}
document.write(hours + ":" + mins + ":" + secs);
document.getElementById(tzcd).innerHTML = hours + ':' + mins + ':' + secs;
setTimeout('displayTZCountDown(' + (countdown - 1) + ',\'' + tzcd + '\');', 999);
}
</script>
</head>
<body>
<div id="sidebar-top">
<div id="inner">
<script>
start('9', '25', '12', '00', '00', 'myTimerID');
</script>
</div>
</div>
</body>
</html>