日期:2014-05-16  浏览次数:20429 次

我怎么让这个摇奖机停下来?
<html>
<head> <meta   http-equiv= "Content-Type "   content= "text/html;charset=gb2312 ">
<title> 闪烁的图片 </title>
</head>

<body>
<div   id= "soccer "   style= "position:absolute;left:150;top:54;width:120;height:42 ">
<span   id= "firstNum "   style= "font-size:30pt "> 0 </span>
<span   id= "secondNum "   style= "font-size:30pt "> 0 </span>
<span   id= "thirdNum "   style= "font-size:30pt "> 0 </span>
<span   id= "fourthNum "   style= "font-size:30pt "> 0 </span>
</div>
<div>
<input   type= "button "   value= "开始 "   onclick= "start1() "> <input   type= "button "   value= "停止 "   onclick= "stop() ">
</div>

<script   language= "javascript ">
var   msecs   =   10;
var   t;
function   start1(){
var   t   =   setTimeout( "blink() ",msecs);
}

function   blink(){
var   firstNum   =   document.getElementById( "firstNum ");
firstNum.innerText   =   parseInt(Math.random()   *   10);
secondNum.innerText   =   parseInt(Math.random()   *   10);
thirdNum.innerText   =   parseInt(Math.random()   *   10);
fourthNum.innerText   =   parseInt(Math.random()   *   10);
t   =   setTimeout( "blink() ",msecs);
}

function   stop(){
clearTimeout(t);
}
</script>

</body>
</html>

这个程序运行正常,但是有个小bug——
如果我点3次“开始”,那要点3次“停止”才能让它停下来
请问怎样修改程序,无论怎么点“开始”,点一次“停止”就能停下来?

------解决方案--------------------
<html>
<head> <meta http-equiv= "Content-Type " content= "text/html;charset=gb2312 ">
<title> 闪烁的图片 </title>
</head>

<body>
<div id= "soccer " style= "position:absolute;left:150;top:54;width:120;height:42 ">
<span id= "firstNum " style= "font-size:30pt "> 0 </span>
<span id= "secondNum " style= "font-size:30pt "> 0 </span>
<span id= "thirdNum " style= "font-size:30pt "> 0 </span>
<span id= "fourthNum " style= "font-size:30pt "> 0 </span>
</div>
<div>
<input id= "start " type= "button " value= "开始 " onclick= "start1() "> <input id= "end " type= "button " value= "停止 " disabled onclick= "stop() ">
</div>

<script language= "javascript ">
var msecs = 10;
var t;
function start1(){
event.srcElement.disabled=true;
document.getElementById( "end ").disabled=false;
var t = setTimeout( "blink() ",msecs);
}

function blink(){
var firstNum = document.getElementById( "firstNum ");
firstNum.innerText = parseInt(Math.random() * 10);
secondNum.innerText = parseInt(Math.random() * 10);
thirdNum.innerText = parseInt(Math.random() * 10);
fourthNum.innerText = parseInt(Math.