<!DOCTYPE html><html><head>? ? <meta charset="UTF-8">? ? <title>Document</title><script type="text/javascript">var i=setInterval(clock,1000);function clock() {var mytime =new Date();var year ? =mytime.getFullYear();var month ?=mytime.getMonth();var date ? =mytime.getDate();var week ? =mytime.getDay();var weeks ?=["日","一","二","三","四","五","六"];var day ? ?=weeks[week];var hour ? =mytime.getHours();var minute =mytime.getMinutes();var second =mytime.getSeconds();time_now ? =year+"年"+(month+1)+"月"+date+"日"+"星期"+day+hour+":"+minute+":"+second;document.getElementById('txt').value=time_now;}function start() {i=setInterval(clock,1000); ? /*我的問題:為什么如果這行寫成“var?i=setInterval(clock,1000)",第二次單擊stop時stop按鈕就失效了呢?為嘛非得去掉這個"var"?*/}</script></head><body><input type="text" id="txt" style="width:200px"><input type="button" onclick="start()" value="start"><input type="button" onclick="clearInterval(i)" value="stop"></body></html>
為什么start()函數(shù)里寫成 “var i=setInterval(clock,1000);” 就不行了?
Candy3610866
2016-08-08 15:05:24