您的位置:首页 > Web前端 > HTML

这个程序有Bug

2012-10-10 09:40 211 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>动态数字</title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="!" />
<style>
#first{
margin:80px auto;
font-size:48px;
color:blue;
text-align:center;
background:#E66200;
width:300px;
height:100px;
line-height:100px;
}
#second{
text-align:center;
height:50px;
line-height:50px;
}
#main{
margin:50px auto;
text-align:center;
width:500px;
border:1px solid red;
}
</style>
</head>
<body>
<div id = "main">
<div id = "first">0</div>
<script>
var divObj = document.getElementById("first");
var i = 1;
var dt = null;
function starter(){
dt = window.setInterval(function()
{
divObj.innerHTML = i;
i++;
},100);}

function reseter()
{
i=0;
divObj.innerHTML = i;
}
function stoper()
{
window.clearInterval(dt);
}
</script>
<div id = "second">
<form>
<input type = "button" name = "start" value = "开始" onclick = "starter()" />
<input type = "button" name = "stop" value = "停止" onclick = "stoper()" />
<input type = "button" name = "reset" value = "重置" onclick = "reseter()">
</form>
</div>
</div>
</body>
</html>
代码如上,最后在浏览器中运行的结果如上图所示,当点击“开始”时,数字开始动态的逐渐递增;点击“停止”,数字停止不再增加;点击“重置”,则数字从0重新开始。可出现了如下的错误:在数字增加的过程中,如果再一一次点击“开始”并点击“停止”时,数字就无法停止了。这是为什么?因为初学,根本不能找到bug,还请各位大牛帮助小弟找到上面代码中的bug。谢谢。
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐