时间停止和继续问题,代码贴在下面,为何先点击继续时间按钮就不能停止了,停止按钮无效了,怎么回事?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>定时器</title>
<script type="text/javascript">
var attime,stop;
function clock(){
var time=new Date();
attime=time.getHours()+":"
+time.getMinutes()+":"
+time.getSeconds();
document.getElementById("clock").value = attime;
}
stop=setInterval(clock,100);
function fun1(){
clearInterval(stop);
alert("时间停止!");
}
function fun2(){
stop=setInterval(clock,100);
alert("时间继续!");
}
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="点击我停止时间" onclick="fun1()">
<input type="button" value="点击我继续时间" onclick="fun2()">
</form>
</body>
</html>