<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.random() * 10);
t = setTimeout("blink()",msecs);
}function stop(){
clearTimeout(t);
event.srcElement.disabled=true;
document.getElementById("start").disabled=false;
}
</script></body>
</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.random() * 10);
t = setTimeout("blink()",msecs);
}function stop(){
clearTimeout(t);
event.srcElement.disabled=true;
document.getElementById("start").disabled=false;
}
</script></body>
</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="停止" onclick="stop()">
</div><script language="javascript">
var msecs = 10;
var t;
var IsStop=true;
function start1(){
if(!IsStop)return;
else IsStop=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.random() * 10);
t = setTimeout("blink()",msecs);
}function stop(){ clearTimeout(t);
if(IsStop)return;
else IsStop=true;
}
</script></body>
</html>
因为这儿写的是两个按钮,但实际使用时我可能要用两个图片来代替这两个按钮
图片应该没有disabled属性吧
<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;
var isStart = false;
function start1(){
if(isStart == false)
{var t = setTimeout("blink()",msecs); isStart=true;}}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);
isStart=false;
}
</script></body>
</html>加个全局变量OK