i關于局部變量的問題
i 在timedCount( )中定義了,不是只在這個函數(shù)中有效嗎?
為什么在stopCount( )中還有效呢?
function timedCount(){
? ? document.getElementById('txt').value=num;
? ? num=num+1;
? ? i=setTimeout(timedCount,1000);
? }
? function stopCount(){
? ? clearTimeout(i);
? }
i 在timedCount( )中定義了,不是只在這個函數(shù)中有效嗎?
為什么在stopCount( )中還有效呢?
function timedCount(){
? ? document.getElementById('txt').value=num;
? ? num=num+1;
? ? i=setTimeout(timedCount,1000);
? }
? function stopCount(){
? ? clearTimeout(i);
? }
2016-09-03
舉報
2016-09-03
在JavaScript里,
如果一個函數(shù)體里的 (也就是function timedCount(){})中申明的變量沒有使用var?
那么這個變量將會變成全局變量。