直接上代码吧,效果可以复制了去看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<style type="text/css">
.a1
{
position: relative;
font-family: Verdana;
font-size: 200px;
color: #888888;
}
</style>
<script language="JavaScript">
function Lottery() {
var Nos = Math.round(Math.random() * (4999 - 1) + 1);
var result = document.getElementById("layer1");
if (result != null) {
result.innerHTML = Nos;
}
T = setTimeout('Lottery()', 30);
}
//-->
</script>
</head>
<body>
<div>
<input type="button" value='Lottery Number Picker' onclick="Lottery();setTimeout('clearTimeout(T)',2000);" />
</div>
<div>
<span id="layer1" class="a1">Result</span>
</div>
</body>
</html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<style type="text/css">
.a1
{
position: relative;
font-family: Verdana;
font-size: 200px;
color: #888888;
}
</style>
<script language="JavaScript">
function Lottery() {
var Nos = Math.round(Math.random() * (4999 - 1) + 1);
var result = document.getElementById("layer1");
if (result != null) {
result.innerHTML = Nos;
}
T = setTimeout('Lottery()', 30);
}
//-->
</script>
</head>
<body>
<div>
<input type="button" value='Lottery Number Picker' onclick="Lottery();setTimeout('clearTimeout(T)',2000);" />
</div>
<div>
<span id="layer1" class="a1">Result</span>
</div>
</body>
</html>
补充:
后来我在调试程序的过程中发现,以上程序在Firefox中运行良好,但是在IE7经常会出现数字停不下来的情况,把Lottery()的递归时间从10毫秒改到30毫秒以后问题解决。