我想问一下,如果把计数器改成显示当前时间不断刷新,但是点击“stop”按钮可以停下计时,如果再单击的时候可以刷新当前时间并计时,怎么弄呢?以下是我的代码,感觉少了什么东西,但是不知道怎么加上去
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>计时器延迟时间</title>
<script type="text/javascript">
var num=new Date();
var i;
var n;
i=setInterval("startCount()",1000);
function startCount(){
var num=new Date();
n=num.getTime()+1;
document.getElementById('count').value=num;
i=setTimeout("startCount()",1000);
}
function stopCount(){
var j=clearTimeout(i);
}
</script>
</head>
<body>
<form>
<input type="text" id="count" size="50" readonly="readonly" />
<input type="button" value="Start" onclick="startCount()"/>
<input type="button" value="Stop" onclick="stopCount()"/>
</form>
</body>
</html>