多个经过时间的计数器

时间:2013-05-05 20:18:41

标签: javascript html elapsedtime

我成功利用以下代码在网页上显示1个已用的计时器。 我希望能够在同一页面上显示几个经过时间的计数器,每个TEAM一个。

我能够通过复制整个代码来实现这一点,但这使得在需要时很难找到要编辑的日期。

是否可以在代码的一个部分列出每个团队的所有日期?

EG。

id='ClockTEAM2' edate1="2/11/2009 00:00:00
id='ClockTEAM2' edate2="12/06/2012 00:00:00

非常感谢任何帮助

TEAM1
<td align="middle">
<font color="#00309c">
<span name="ClockTEAM1" id='ClockTEAM1' edate="2/11/2009 00:00:00">



<script language="Javascript">
function displaydatetime() {

 var today = new Date();
  var oSpan = document.all.tags("span");
  if ( typeof(oSpan) != "undefined" )
  {
      for (var i=0; i<oSpan.length; i++)
      {
          if ( oSpan[i].name == "ClockTEAM1" )
          {
              startday = new Date(oSpan[i].edate);
              secsPerDay = 1000 ;
              minPerDay = 60 * 1000 ;
              hoursPerDay = 60 * 60 * 1000;
              PerDay = 24 * 60 * 60 * 1000;
              secsLeft = (today.getTime() - startday.getTime()) / minPerDay;
              secsRound = Math.round(secsLeft);
              secsRemain = secsLeft - secsRound;
              secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60;
              secsRemain = Math.round(secsRemain);
              minLeft = ((today.getTime() - startday.getTime()) / hoursPerDay);
              minRound = Math.round(minLeft);
              minRemain = minLeft - minRound;
              minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft) * 60) : minRemain = ((minLeft - minRound) * 60);
              minRemain = Math.round(minRemain - 0.495);
              hoursLeft = ((today.getTime() - startday.getTime()) / PerDay);
              hoursRound = Math.round(hoursLeft);
              hoursRemain = hoursLeft - hoursRound;
              hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - hoursLeft) * 24)  : hoursRemain = ((hoursLeft - hoursRound) * 24);
              hoursRemain = Math.round(hoursRemain - 0.5);
              daysLeft = ((today.getTime() - startday.getTime()) / PerDay);
              daysLeft = (daysLeft - 0.5);
              daysRound = Math.round(daysLeft);
              daysRemain = daysRound;

              if (secsRemain > 59)
              {
                  secsRemain = "0";
                  if (minRemain > 59)
                  {
                       minRemain = "0";
                       if (hoursRemain > 23)
                       {
                            hoursRemain = "0";
                            if (daysRemain>364)
                            {
                                 daysRemain = "0";
                            }
                        }
                   }
              }

              secsRemain = (secsRemain < 10) ? secsRemain = "0" + secsRemain : secsRemain;
              minRemain = (minRemain < 10) ? minRemain = "0" + minRemain : minRemain;                                                          
              timeRemain = daysRemain + " Days " +     hoursRemain + ":" + minRemain + ":" +         secsRemain;                                             
              oSpan[i].innerHTML = timeRemain;
          }
       }          
       timerID=setTimeout("displaydatetime()", 1000)

       timerRunning = true;
  }
}
displaydatetime();



</script>
</span>
</font>
</td>
</tr>
</table>

1 个答案:

答案 0 :(得分:0)

确定您遇到的问题确切无误。您是否尝试将两个跨度相继放置?