為什么要加兩個setTimeout
<!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>
加兩個setTimeout就一秒增加兩個數(shù)了,然后按停止也要按兩下才會停止 ,所以后面加setTimeout的意義是什么
2018-07-24
我的理解:第一個構(gòu)成了循環(huán),第二個是開始執(zhí)行函數(shù)
2018-06-27
為了一開打頁面就啟動計時器