增加了一个“start”按钮,如何实现点击“start”按钮后开始计时,而点击“stop”按钮后结束计时呢?下面的代码实现不了,只能实现点击“stop”结束计时,但点击“start”只跳出一次时间,而无法继续计时。。。请高手指点!谢谢!
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>计时器</title>
<script type="text/javascript">
var i;
function start(){
var time=new Date();
document.getElementById("myclock").value = time;
// i=setInterval("start()",1000);
}
i=setInterval("start()",1000);
function stop(){
// i=setInterval("start()",1000);
clearInterval(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="myclock" size="50" />
<input type="button" value="Start" onclick="start()" />
<input type="button" value="Stop" onclick="stop()" />
</form>
</body>
</html>