為什么加了一個時間恢復(fù)的按鈕,然后再按停止卻沒用了?
<!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 的恢復(fù) 按鈕,按了一下確實恢復(fù)了,但是再按停止的時候就不行了,為什么?
2016-11-29
?function clock(){
? ? ? var time=new Date(); ? ? ? ? ? ? ? ? ? ??
? ? ? document.getElementById("clock").value = time;
? ?}
? ?var timer = setInterval(clock);
? ?function stop(){
? ? clearInterval(timer);
? ?}
? ?function start(){
? ? timer = setInterval(clock);
? ?}