為什么start按鈕時不能直接設置setInterval()
<!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 i=setInterval("clock()",100)
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50"? />
? ? <input type="button" value="Stop"? onclick="clearInterval(i)"/>
? ? <input type="button" value="開始" onclick="setInterval(clock,100)">
? </form>
</body>
</html>
2018-12-24
你問的是 為啥setInterval () 沒有在點擊事件中生效吧? ? ?我查看控制臺反饋的是寫入出錯? ?
這個問題? 有點難度? 挖個坑回頭再來填