啟用計(jì)時(shí)器和關(guān)閉計(jì)時(shí)器,關(guān)閉計(jì)時(shí)器時(shí)無效
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>計(jì)時(shí)器</title>
</head>
<script type="text/javascript">
/*
? var num=0;
? var i;
? function startCount(){
? ? document.getElementById('count').value=num;
? ? num=num+1;
? ? i=setTimeout("startCount()",1000);
? }
? function stopCount(){
? clearTimeout(i);
? }
*/
? var num=0;
? function startCount(){
? ? document.getElementById('count').value=num;
? ? num+=1;
? ?var 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>
//上面未注釋代碼哪里錯(cuò)了,怎么無效呢?
2016-02-02
i 為局部變量 作用范圍只在startCount()函數(shù)中 ,將i定義在函數(shù)的外邊
2016-02-24
你的num+=1是什么意思。。