webForumDet fria alternativet

Lägg till tiondelar i min timer

2 svar · 310 visningar · startad av Mattias Nordin

Mattias NordinMedlem sedan dec. 20051 056 inlägg
#1

Jag använder mig av följande skript (som jag inte själv har skrivit) och undrar om man på ett enkelt sätt kan lägga till så att den även visar tiondelar av en sekund.

Hjälp mottages tacksamt.


var timerID = 0;
var tStart  = null;

function UpdateTimer() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }
   if(!tStart)
    	tStart   = new Date();
   		var tDate = new Date();
   		var tDiff = tDate.getTime() - tStart.getTime();
   tDate.setTime(tDiff);
   document.theTimer.theTime.value = "" + tDate.getMinutes() + ":"  + tDate.getSeconds();
   timerID = setTimeout("UpdateTimer()", 1000);
}

function Start() {
   tStart   = new Date();
   document.theTimer.theTime.value = "00:00";
   timerID  = setTimeout("UpdateTimer()", 1000);
}
aspMedlem sedan aug. 2002733 inlägg
#2

...

nitro2k01Medlem sedan aug. 20039 342 inlägg
#3
var timerID = 0;
var tStart  = null;

function UpdateTimer() {
   if(timerID) {
      clearTimeout(timerID);
      clockID  = 0;
   }
   if(!tStart)
    	tStart   = new Date();
   		var tDate = new Date();
   		var tDiff = tDate.getTime() - tStart.getTime();
   tDate.setTime(tDiff);
   document.theTimer.theTime.value = "" + tDate.getMinutes() + ":"  + tDate.getSeconds() [u]+ "." + tDate.getMilliseconds()[/u];
   timerID = setTimeout("UpdateTimer()", [u]100[/u]);
}

function Start() {
   tStart   = new Date();
   document.theTimer.theTime.value = "00:00";
   timerID  = setTimeout("UpdateTimer()", [u]100[/u]);
}

Ändrad/tillagd kod markerad med understrykning. Som vanligt med mina svar är koiden bara testad i mitt huvud.

Får jag gissa att V&S ska ha någon slags frågesport på sin hemsida? ;)

254 ms totalt · 3 externa anrop · v20260731065814-full.30151723
132 ms — hämta forumlista (db)
120 ms — hämta statistik (db)
130 ms — hämta tråd, inlägg och bilagor (db)