The setTimeout method is a timed program, that is, at what time to do. After finishing it, it will be over.
The setInterval method means that a certain operation is repeatedly executed during a certain interval.
If you use setTimeout to implement the function of setInterval, you need to call yourself regularly in the executed program. If you want to clear the counter, you need to call different clear methods according to the method used:
For example:
tttt=setTimeout('northsnow()',1000);
clearTimeout(tttt);
or:
tttt=setInterval('northsnow()',1000);
clearInteval(tttt);
To give an example:
<div ></div>
<input type="button" name="start" value="start" onclick='startShow();'>
<input type="button" name="stop" value="stop" onclick="stop();">
<script language="javascript">
var intvalue=1;
var timer2=null;
function startShow()
{
= + " " + (intvalue ++).toString();
timer2=("startShow()",2000);
}
function stop()
{
(timer2);
}
</script>
or:
<div ></div>
<input type="button" name="start" value="start" onclick='timer2=("startShow()",2000);//startShow();'>
<input type="button" name="stop" value="stop" onclick="stop();">
<script language="javascript">
var intvalue=1;
var timer2=null;
function startShow()
{
= + " " + (intvalue ++).toString();
}
function stop()
{
(timer2);
}
</script>
The setInterval method means that a certain operation is repeatedly executed during a certain interval.
If you use setTimeout to implement the function of setInterval, you need to call yourself regularly in the executed program. If you want to clear the counter, you need to call different clear methods according to the method used:
For example:
tttt=setTimeout('northsnow()',1000);
clearTimeout(tttt);
or:
tttt=setInterval('northsnow()',1000);
clearInteval(tttt);
To give an example:
Copy the codeThe code is as follows:
<div ></div>
<input type="button" name="start" value="start" onclick='startShow();'>
<input type="button" name="stop" value="stop" onclick="stop();">
<script language="javascript">
var intvalue=1;
var timer2=null;
function startShow()
{
= + " " + (intvalue ++).toString();
timer2=("startShow()",2000);
}
function stop()
{
(timer2);
}
</script>
or:
Copy the codeThe code is as follows:
<div ></div>
<input type="button" name="start" value="start" onclick='timer2=("startShow()",2000);//startShow();'>
<input type="button" name="stop" value="stop" onclick="stop();">
<script language="javascript">
var intvalue=1;
var timer2=null;
function startShow()
{
= + " " + (intvalue ++).toString();
}
function stop()
{
(timer2);
}
</script>