Niedziela 19 Maj 2024r. Godz 00:00:00      
Postów: 251      

Stoper w JavaScript

: :


<SCRIPT LANGUAGE="Javascript1.2">
<!-- begin hide
var currentsec=0; // initilize variables
var currentmin=0; // to zero
var currentmil=0;
var keepgoin=false;  // keepgoin is false
function timer(){
 if(keepgoin){
  currentmil+=1;  // add incretement
   if (currentmil==10){  // if miliseconds reach 10
    currentmil=0;  // Change miliseconds to zero
    currentsec+=1;  // and add one to the seconds variable
   }
   if (currentsec==60){  // if seconds reach 60
    currentsec=0;  // Change seconds to zero
    currentmin+=1;  // and add one to the minute variable
   }
  Strsec=""+currentsec;  // Convert to strings
  Strmin=""+currentmin;  // Convert to strings
  Strmil=""+currentmil;  // Convert to strings
   if (Strsec.length!=2){ // if seconds string is less than
    Strsec="0"+currentsec; // 2 characters long, pad with leading
   }    // zeros
   if (Strmin.length!=2){ // Same deal here with minutes
    Strmin="0"+currentmin;
   }
  document.display.seconds.value=Strsec  // displays times
  document.display.minutes.value=Strmin; // here
  document.display.milsecs.value=Strmil;
  setTimeout("timer()", 100); // waits one second and repeats
 }
}
function startover(){  // This function resets
keepgoin=false;   // all the variables
currentsec=0;
currentmin=0;
currentmil=0;
Strsec="00";
Strmin="00";
Strmil="00";
}
//--end hide -->
</SCRIPT>

<FORM NAME="display" ONRESET="startover()">
<TABLE BORDER=10 BGCOLOR="#777777">
<TR><TD BGCOLOR="#000000" COLSPAN=3>
<DIV STYLE="font-size:35px;font-family:LCD,Sans Serif;color:#00ff00">
 <INPUT TYPE="text" NAME="minutes" VALUE="00" SIZE=3 STYLE="height:30px;border:0;font-size:30px;width:33px;font-family:LCD,Sans Serif;color:#00ff00;background:#000000">
:
<INPUT TYPE="text" NAME="seconds" VALUE="00" SIZE=3 STYLE="height:30px;border:0;font-size:30px;width:35px;font-family:LCD,Sans Serif;color:#00ff00;background:#000000">
:
<INPUT TYPE="text" NAME="milsecs" VALUE="0" SIZE=3 STYLE="height:30px;border:0;font-size:30px;width:20px;font-family:LCD,Sans Serif;color:#00ff00;background:#000000">
</TD></TR><TR><TD CELLPADDING=5>
<INPUT TYPE="button" NAME="start" VALUE="Start" ONCLICK="keepgoin=true;timer()">
</TD><TD>
<INPUT TYPE="button" NAME="pause" VALUE="Pause" ONCLICK="keepgoin=false;">
</TD><TD>
<INPUT TYPE="reset" NAME="reset" VALUE="Reset">
</TD></TR></TABLE>
</FORM>