时间:2021-07-01 10:21:17 帮助过:12人阅读
<div id="liujincai"></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()
{
liujincai.innerHTML=liujincai.innerHTML + " " + (intvalue ++).toString();
timer2=window.setTimeout("startShow()",2000);
}
function stop()
{
window.clearTimeout(timer2);
}
</script>
或者:
代码如下:
<div id="liujincai"></div>
<input type="button" name="start" value="start" onclick='timer2=window.setInterval("startShow()",2000);//startShow();'>
<input type="button" name="stop" value="stop" onclick="stop();">
<script language="javascript">
var intvalue=1;
var timer2=null;
function startShow()
{
liujincai.innerHTML=liujincai.innerHTML + " " + (intvalue ++).toString();
}
function stop()
{
window.clearInterval(timer2);
}
</script>