JS page timer sample code

  • 2020-03-26 21:42:51
  • OfStack

 
<html> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<head> 
<script type="text/javascript"> 
var c=0 
var t 
function timedCount() 
{ 
document.getElementById('txt').value=c 
c=c+1 
t=setTimeout("timedCount()",1000) 
} 
function stopCount() 
{ 
clearTimeout(t) 
} 
</script> 
</head> 
<body> 
<form> 
<input type="button" value=" Start the clock! " onClick="timedCount()"> 
<input type="text" id="txt"> 
<input type="button" value=" Stop the clock! " onClick="stopCount()"> 
</form> 
<p> Please click the start timer button above to start the timer. The input box will keep timing from  0  Start. Click the "stop timing" button to terminate the timing. </p> 
<p>timedCount(),1000ms Adjust yourself. </p> 
</body> 
</html> 

Related articles: