我的腳本有什麼問題?當我執行它時,警報(第2行)給了我「100,200,300undefinedundefined」,所以當我希望它是h1,h2和h3(用逗號)時,似乎100,200,300被解釋爲h1。Javascript函數變量問題
function myanimation(h1,h2,h3) {
alert(h1 + h2 + h3);
$("#h1").animate({"left": h1});
$("#h2").animate({"left": h2});
}
var moves = new Array()
moves[1] = [100,200,300];
moves[2] = [300,200,100];
moves[3] = [-500,-300,0];
var i = 1;
function animatenow(){
myanimation(moves[i]);
i++;
}
$('#launch').click(function() {
setInterval(animatenow, 5000);
});
另一個問題:當我在我的函數中使用i ++時,它不起作用;它總是發送移動[1],所以我如何使i ++範圍成爲全局而不是本地? – 2012-04-19 18:26:59
@AdamStrudwick它不會那樣對我。有沒有其他的代碼可能會重置我? – 2012-04-19 20:00:41