Please login to start chat

timer (HTML DOM Window)

Created on : 25 Jun 2022, 11:39:36

<!DOCTYPE html>
<html>
<head>
<title>Js Code Testing</title>
</head>
<body>
<button onclick = "startCount()">Start Count</button>
<input type = "text" id = "txt">
<button onclick = "stopCount()">Stop Count</button>
</body>
<script>
var c = 0;
var t;
var myTimer = 0;

function jsFun(){
document.getElementById("txt").value = c;
c++;
t = setTimeout(jsFun, 1000);
}

function startCount(){
if(!myTimer){
myTimer = 1;
jsFun();
}
}

function stopCount(){
myTimer = 0;
clearTimeout(t);
}
</script>
</html>

Comments:

No Commments to show

About Me
Blog and Ambitions
Terms and Conditions
Contact Me
Service and Guarantee
Customers and News
Carrers