gpt4 book ai didi

jquery - Javascript函数变量问题

转载 作者:行者123 更新时间:2023-12-01 02:07:03 26 4
gpt4 key购买 nike

我的脚本有什么问题?当我执行它时,警报(第 2 行)给我“100,200,300undefineundefined”,所以当我希望它是 h1、h2 和 h3(带逗号)时,似乎 100,200,300 被解释为 h1。

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);
});

最佳答案

您正在将一个数组传递给 myanimation,它对应于您的 h1 参数。您没有传递 h2h3,因此这些未定义。

关于jquery - Javascript函数变量问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10233788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com