為什么stop只能停止一次?代碼如下:
我在本地測試了一下下面的代碼,點停止后,時間會停止,再點開始,會開始,可再點停止就不管用了,為什么呢?
<!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,1000)
? ?function start(){
? ? ? ?setInterval(clock,1000)
? ? ? ?
? ?}
? ??
</script>
</head>
<body>
? <form>
? ? <input type="text" id="clock" size="50" ?/>
? ? <input type='button' value='Start' onclick='start()'>
? ? <input type="button" value="Stop" ?onclick='clearInterval(i)'/>
? </form>
</body>
</html>
2015-04-07
把你代碼放在本地嘗試一下