weibo_吾乃凤凰院凶真3999740
2016-11-29 11:20
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>计时器</title> <script type="text/javascript"> function clock(){ var time=new Date(); document.getElementById("clock").value = time; } var stop=setInterval(clock,100); function start(){ var stop=setInterval(clock,100); } </script> </head> <body> <form> <input type="text" id="clock" size="50" /> <input type="button" value="Stop" onclick="clearInterval(stop)" /> <input type="button" value="start" onclick="start()" /> </form> </body> </html>
加了一个start 的恢复 按钮,按了一下确实恢复了,但是再按停止的时候就不行了,为什么?
function clock(){
var time=new Date();
document.getElementById("clock").value = time;
}
var timer = setInterval(clock);
function stop(){
clearInterval(timer);
}
function start(){
timer = setInterval(clock);
}
JavaScript进阶篇
468194 学习 · 21891 问题
相似问题