為什么按stop無法停止計(jì)時(shí)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</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)"/>
? </form>
</body>
</html>
2016-06-01
你的代碼沒有問題,是慕課的bug。
解決方法:敲好代碼后首先提交(為了保存代碼),之后刷新頁面就可以了。這樣你就可以看到clearInterval()的效果了。
2016-05-19
我用的谷歌瀏覽器也沒法暫停時(shí)間
2016-05-13
用IE8.0和火狐試了。都可以啊。瀏覽器問題吧