var a=0;
setTimeout (function() { animatedDraw(context, 20+32*level[0],20*0, textArray[0]); }, timeArray[0]);
setTimeout (function() { animatedDraw(context, 20+32*level[1],20*1, textArray[1]); }, timeArray[1]);
setTimeout (function() { animatedDraw(context, 20+32*level[2],20*2, textArray[2]); }, timeArray[2]);
setTimeout (function() { animatedDraw(context, 20+32*level[3],20*3, textArray[3]); }, timeArray[3]);
setTimeout (function() { animatedDraw(context, 20+32*level[4],20*4, textArray[4]); }, timeArray[4]);
setTimeout (function() { animatedDraw(context, 20+32*level[5],20*5, textArray[5]); }, timeArray[5]);
for (a=0; a<6; a++)
setTimeout (function() { animatedDraw(context, 20+32*level[a],20*0, textArray[a]); }, timeArray[a]);
我的代碼的第一部分是工作的部分。第二部分沒有出現。我正在繪製一個畫布(HTML 5),但是當我彈出六個警報框時,警示框顯示出來。 我在做什麼非常愚蠢的錯誤?JavaScript,for循環將不起作用
在此先感謝
我會接受你的答案時,我可以。謝謝,這正是我的問題!當我減少我的循環時,最後的聲明顯示。 – Hidde 2011-06-15 18:49:29
@Michael:不,這沒有幫助,因爲如果它在函數內部,它在函數運行時仍然使用'a'。你需要一個工廠或類似的東西;我已經添加了一個例子。 – 2011-06-15 18:50:38
@Hidde:很高興幫助。我添加了一個如何處理它的例子。 – 2011-06-15 18:51:05