<!DOCTYPE html>
<html>
<body>
<p>A script on this page starts(Interval dynamically) and stop</p>
<p id="demo"></p>
<input id="intervalValue"type="text">
<button onclick="myStartFunction()">Start</button>
<button onclick="myStopFunction()">Stop </button>
<script>
var myVar;
function myTimer() {
for(var index=0;index<5;index++){
console.log(index);
}
}
function myStopFunction() {
clearInterval(myVar);
}
function myStartFunction(){
var theIntervalValue = document.getElementById("intervalValue");
myVar = setInterval(function(){ myTimer() }, theIntervalValue);
}
</script>
</body>
</html>
A script on this page starts(Interval dynamically) and stop
<html>
<body>
<p>A script on this page starts(Interval dynamically) and stop</p>
<p id="demo"></p>
<input id="intervalValue"type="text">
<button onclick="myStartFunction()">Start</button>
<button onclick="myStopFunction()">Stop </button>
<script>
var myVar;
function myTimer() {
for(var index=0;index<5;index++){
console.log(index);
}
}
function myStopFunction() {
clearInterval(myVar);
}
function myStartFunction(){
var theIntervalValue = document.getElementById("intervalValue");
myVar = setInterval(function(){ myTimer() }, theIntervalValue);
}
</script>
</body>
</html>
No comments:
Post a Comment