javascript - 没有在我的网页中获得倒计时功能

标签 javascript timer countdown

我正在制作一个竞赛平台..为此我需要一个倒数计时器..问题是我不会 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>

最佳答案

查看您的脚本,您的 HTML 似乎缺少 ID 为“myTimerID”的元素

关于javascript - 没有在我的网页中获得倒计时功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11224768/

相关文章:

javascript - PHP 和 JQuery - PHP json_encoded 2D 数组未到达 JQuery Ajax

javascript - 客户端本地化

jquery - 设置超时控件

ios - 如何在 Swift 中为 OTP 倒计时

javascript倒计时并显示毫秒

javascript - 为什么这个JS倒计时不起作用?

javascript - 编写标记并使用 jQuery Toggle 删除

javascript - 使用 PHP 进行淡出的更好方法

javascript - 应用程序在后台时 setInterval 函数不运行

c - 虚拟时间已过