为什么把变量time声明放在函数体外,按start就不能进行计时?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器1</title>
<script type="text/javascript">
var time=new Date();
function clock(){
//var time=new Date();
document.getElementById("clock").value = time;
}
var i;
function start() {
clearInterval(i);
i=setInterval(clock,100);
}
function stop() {
clearInterval(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="clock" size="50" />
<input type="button" value="Stop" onclick="stop()" />
<input type="button" value="Start" onclick="start()" />
</form>
</body>
</html>