下面是我的代碼,為什么start和stop兩個(gè)按鈕不管用哎
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</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
沒(méi)有問(wèn)題啊? 慕課網(wǎng)網(wǎng)頁(yè)問(wèn)題吧
2018-11-28
錯(cuò)誤如下:
2018-11-28
我的代碼:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</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
你這個(gè)代碼不會(huì)點(diǎn)擊觸發(fā)函數(shù)。而是直接觸發(fā),因?yàn)槟阍趕tartCount()下面又加了一個(gè)setTimeout("startCount()",1000);這樣的定時(shí)器,所以它會(huì)隔1秒后直接執(zhí)行你上面的這個(gè)startCount()函數(shù),
所以你點(diǎn)擊開(kāi)始是沒(méi)用的,但是你點(diǎn)擊停止有用,然后再點(diǎn)擊開(kāi)始也是可以的
2018-11-25