How to Start count and Brack timer clearTimeout() in Jquery
Start count and Brack timer clearTimeout() in Jquery,How to Start count and Brack timer clearTimeout() in Jquery
<!DOCTYPE html>
<html>
<body>
<button onclick="startCount()">Start count!</button>
<input type="text" id="txt">
<button onclick="stopCount()">Stop count!</button>
<p>
Click on the "Start count!" button above to start the timer. The input field will count forever, starting at 0. Click on the "Stop count!"
<br/> button to stop the counting. Click on the "Start count!" button to start the timer again.
</p>
<script>
var c = 0;
var t;
var timer_is_on = 0;
var myCounter = 0;
function timedCount() {
document.getElementById("txt").value = c;
c = c + 1;
t = setTimeout(timedCount, 1000);
myCounter = myCounter + 1
if(myCounter == 100)
{
c = 0;
t;
timer_is_on = 0;
myCounter = 0;
clearTimeout(t);
timer_is_on = 0;
}
}
function startCount() {
if (!timer_is_on) {
timer_is_on = 1;
timedCount();
}
}
function stopCount() {
c = 0;
t;
timer_is_on = 0;
myCounter = 0;
clearTimeout(t);
timer_is_on = 0;
}
</script>
</body>
</html>
*we won't spam you
Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk
Post A Comment:
0 comments: