下面是我的代碼,為什么start和stop兩個按鈕不管用哎
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計時器</title>
<script type="text/javascript">
? var num=0;
? var i;
? function startCount(){
? ? document.getElementById('count').value=num;
? ? num=num+1;
? ? i=setTimeout("startCount()",1000);
? }
? setTimeout("startCount()",1000);
? function stopCount(){
? ? clearTimeout(i);
? }
</script>
</head>
<body>
? <form>
? ? <input type="text" id="count" />
? ? <input type="button" value="Start" onClick="startCount()"? />
? ? <input type="button" value="Stop"? onClick="stopCount()" />
? </form>
</body>
</html>
2018-12-14
沒有問題啊? 慕課網網頁問題吧
2018-11-28
錯誤如下:
2018-11-28
我的代碼:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計時器</title>
<script type="text/javascript">
? var num=0,i;
? function startCount() {
? ? ? document.getElementById('count').value=num;
? ? ? num++;
? ? ? i = setTimeout("startCount()",1000);
? }
? function stopCount(){
? ? clearTimeout(i);
? }
</script>
</head>
<body>
? <form>
? ? <input type="text" id="count" />
? ? <input type="button" value="Start" onclick="startCount()" />
? ? <input type="button" value="Stop"? onclick="stopCount()" />
? </form>
</body>
</html>
2018-11-27
你這個代碼不會點擊觸發函數。而是直接觸發,因為你在startCount()下面又加了一個setTimeout("startCount()",1000);這樣的定時器,所以它會隔1秒后直接執行你上面的這個startCount()函數,
所以你點擊開始是沒用的,但是你點擊停止有用,然后再點擊開始也是可以的
2018-11-25