2

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

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

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

例如。

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>
4

1 回答 1

0

不确定你到底遇到了什么麻烦。你试过把两个跨度放在一起吗?

于 2013-05-14T21:59:02.100 回答