Javascript 中clearTimeout 无效果 20
刚学JS不久,求大神指点哪里出错了,想要实现单击抽奖按钮停止这个计时器,但是点击抽奖还是不停止,代码如下:<html><head><metacharset="{CHARS...
刚学JS不久,求大神指点哪里出错了,想要实现单击抽奖按钮停止这个计时器,但是点击抽奖还是不停止,代码如下:
<html>
<head>
<meta charset="{CHARSET}">
<link href="css\ys.css" type="text/css" rel="stylesheet">
<title>幸运大抽奖</title>
</head>
<body>
<div class="all">
<div class="div_banner">
<font class="font_banner">幸运大抽奖</font>
</div>
<div class="div_neirong">
<p class="font_xingyun" id="benqi">本期幸运数字:</p>
<br />
<br />
<p class="font_xingyun" id="ninde">您的幸运数字:</p>
</div>
<div class="div_button">
<button class="button_start" onclick="shengchengsuiji()">开始</button>
<br />
<br />
<br />
<button class="button_choujiang" onclick="stop()">抽奖</button>
</div>
<script>
var again;
var randomnum;
var allword;
function shengchengsuiji()
{
allword=new Array("a","b","c","d","e","f","g","h");
randomnum=Math.round(Math.random()*7);
document.getElementById("benqi").innerHTML="本期幸运数字:"+allword[randomnum];
chongfu();
}
function chongfu()
{
allword=new Array("a","b","c","d","e","f","g","h");
randomnum=Math.round(Math.random()*7);
document.getElementById("ninde").innerHTML="您的幸运数字:"+allword[randomnum];
chongfu2();
}
function chongfu2()
{
again=setTimeout("chongfu()",200);
}
function stop()
{
clearTimeout("again");
}
</script>
</div>
</body>
</html> 展开
<html>
<head>
<meta charset="{CHARSET}">
<link href="css\ys.css" type="text/css" rel="stylesheet">
<title>幸运大抽奖</title>
</head>
<body>
<div class="all">
<div class="div_banner">
<font class="font_banner">幸运大抽奖</font>
</div>
<div class="div_neirong">
<p class="font_xingyun" id="benqi">本期幸运数字:</p>
<br />
<br />
<p class="font_xingyun" id="ninde">您的幸运数字:</p>
</div>
<div class="div_button">
<button class="button_start" onclick="shengchengsuiji()">开始</button>
<br />
<br />
<br />
<button class="button_choujiang" onclick="stop()">抽奖</button>
</div>
<script>
var again;
var randomnum;
var allword;
function shengchengsuiji()
{
allword=new Array("a","b","c","d","e","f","g","h");
randomnum=Math.round(Math.random()*7);
document.getElementById("benqi").innerHTML="本期幸运数字:"+allword[randomnum];
chongfu();
}
function chongfu()
{
allword=new Array("a","b","c","d","e","f","g","h");
randomnum=Math.round(Math.random()*7);
document.getElementById("ninde").innerHTML="您的幸运数字:"+allword[randomnum];
chongfu2();
}
function chongfu2()
{
again=setTimeout("chongfu()",200);
}
function stop()
{
clearTimeout("again");
}
</script>
</div>
</body>
</html> 展开
3个回答
展开全部
setTimeout是只定时一次,如果要循环的话就是要setIntever
追问
我知道,我又让他跳到那个函数里执行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
clearTimeout(again);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
clearTimeout("again");
clearTimeout(again);
clearTimeout(again);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询