关于javascript clearInterval的问题
代码如下:
<script language=javascript>
function clock(){
var t=parseInt(Math.random()*300)
if(t<10){t="00"+t}else{
if(t<100){t="0"+t}}
document.getElementById("shuzi").innerHTML=t
}
function yao(){var abc=setInterval("clock()",100)}
function ting(){clearInterval("abc")}
</script>
<div id="shuzi">预设值</div>
<div class="ank">
<a class="an" href="javascript:yao();">抽奖</a>
<a class="an" href="javascript:ting();">停</a>
</div>
为什么停止不了?
------解决方案--------------------<script language=javascript>
var abc = '';
function clock(){
var t=parseInt(Math.random()*300)
if(t<10){t="00"+t}else{
if(t<100){t="0"+t}}
document.getElementById("shuzi").innerHTML=t
}
function yao(){
abc=setInterval("clock()",100)}
function ting(){clearInterval("abc")}
</script>
<div id="shuzi">预设值</div>
<div class="ank">
<a class="an" href="javascript:yao();">抽奖</a>
<a class="an" href="javascript:ting();">停</a>
</div>