A script to display simple stop watch Click to Test
<!DOCTYPE html>
<html>
<body onload="ts()">
<p>A script to display simple stop watch</p>
<p id="demo"></p>
<button onclick="ts()">Start time</button>
<button onclick="clearInterval(myVar)">Stop time</button>
<script>
s = 0;
m = 0;
h = 0;
function ts()
{
myVar = setInterval(function(){myTimer()},1000);
function myTimer() {
if(s<10)
s = "0"+s;
document.getElementById('demo').innerHTML = h+":"+m+":"+s;
s++;
if ( s==60)
{
m++;
if( m==60)
{
h++;
if(h==24)
{
h=0;
}
m=0;
}
s = 0;
}
}
}
</script>
</body>
</html>
0 comments:
Post a Comment