2012-06-27 25 views
1

我正在製作比賽平臺..爲此我需要一個倒數計時器..問題是,我donno JS ..所以我googled了,並得到這個腳本的計時器..但它不是在網頁上工作...請幫助我.. 這裏是定時器的代碼...我得到的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> 
+0

爲了幫助我們回答您的問題您可能需要閱讀FAQ(http://stackoverflow.com/faq)並查看您是否無法使您的問題更一般和更易於回答。 –

回答

3

看你的腳本,似乎你的HTML缺少ID爲「myTimerID」

+0

我想在div id =「sidebar-top」「inner」中顯示它..我應該怎麼做..我沒有得到輸出,即使我用側邊欄替換myTimerID頂部 –

+0

作了一些修改,但它並不十分清晰腳本應該做什麼或者你想做什麼......但是這裏有一個工作示例: [link](http://jsbin.com/orikos/3/edit#javascript,html)|你需要把id放在你的html的某個地方,而且我必須修正一些javascript的錯字 –

0

順便說一句我做到了完美,small..Just通的元素差異o F中的目標和現在的大紀元時報的功能和它給人的結果:)

function displayTZCountDown(countdown, tzcd) { 
      if (countdown < 0) { 
       document.getElementById(tzcd).innerHTML = "Ended"; 
       window.location="../contest.php"; 
      } 
      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) { 
        hours = "0" + hours; 
       } 
       document.getElementById(tzcd).innerHTML = hours + ':' + mins + ':' + secs; 
       setTimeout('displayTZCountDown(' + (countdown - 1) + ',\'' + tzcd + '\');', 999); 
      } 
     } 

這裏tzcd是HTML的id,我要寫信倒計時targetepoch-currentepoch