Múltiples contadores de tiempo transcurrido

I am successful utilizing the below code to show 1 elapsed timer on a webpage. I'd like to be able to show several elapsed time counters on the same page, one for each TEAM.

I was able to achieve this by duplicating the entire code, though this makes it tough to find the date to edit, when needed.

Is it possible to list all the dates, for each Team, in one sections of the code?

Por ejemplo.

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

Cualquier ayuda sería muy apreciada

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>

preguntado el 05 de mayo de 13 a las 21:05

PLEASE DON'T SHOUT. Use all-upper case sparingly if you don't want to jar our nerves. Thanks for your cooperation in this. Also, how is Java involved here as this looks to be pure JavaScript and HTML? -

You're doing your ternary operation wrongly : not secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) * 60) : secsRemain = (secsLeft - secsRound) * 60; pero : secsRemain = (secsRemain < 0) ? 60 - ((secsRound - secsLeft) * 60) : (secsLeft - secsRound) * 60; -

sorry didn't realize I capitalized a word. Is this the correct application of the process? I'm open to suggestions on another other methods. -

1 Respuestas

Not sure what you're having trouble with exactly. Have you tried placing the two spans right after each other?

contestado el 14 de mayo de 13 a las 22:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.