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