Lägg till tiondelar i min timer

JavaScript

2 svar · 315 visningar · startad av Mattias Nordin

Medlem sedan dec. 20051 056 inlägg
Trådstart#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);
}
Medlem sedan aug. 2002733 inlägg
#2

...

Medlem sedan aug. 20039 340 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? ;)

285 ms totalt · 4 externa anrop · v20260731065814-full.d34c6d5a
129 ms — deklarationer (db)
0 ms — hämta statistik (cache)
147 ms — hämta tråd, inlägg och bilagor (db)
133 ms — ändringar (db)