如何循环访问此表并提取幻灯片的所有信息



>我在jquery中有一个数组,它由问题的答案子集组成,但在用户进入问答 我想向用户显示答案以供记忆。有人可以解释一下如何我可以遍历数组并依次提取每个图像吗?

var imageAnswers = {"q1toQn": [
    {"q1": [
        {"src": "./images/q1/cow", "alt": "cow", "id": "cow"},
        {"src": "./images/q1/horse", "alt": "horse", "id": "horse"},
        {"src": "./images/q1/pig", "alt": "pig", "id": "pig"},
        {"src": "./images/q1/sheep", "alt": "sheep", "id": "sheep"}
    ]},
    {"q2": [
        {"src": "./images/q2/apple_", "alt": "apple", "id": "apple"},
        {"src": "./images/q2/pear_", "alt": "pear", "id": "pear"},
        {"src": "./images/q2/orange_", "alt": "orange", "id": "orange"},
        {"src": "./images/q2/pineapple_", "alt": "pinaapple", "id": "pineapple"}
    ]},
    {"q3": [
        {"src": "./images/q3/chair", "alt": "chair", "id": "chair"},
        {"src": "./images/q3/bookcase", "alt": "bookcase", "id": "bookcase"},
        {"src": "./images/q3/chest", "alt": "chest", "id": "chest"},
        {"src": "./images/q3/table", "alt": "table", "id": "table"}
    ]}, ...

等等

等等

这是我正在做的尝试获取信息:

    var infoTableIndex = 0;
j(function(){
    j("#nextButton").click(
        function(){
            j("#slideshow").not(":animated").animate({"left": "500px", "opacity": "0.3"}, 1000,
            function(i){
                infoTableIndex++;
                j("#slideshow").attr("src", imageAnswers.q1toQn[infoTableIndex].q1[i+1].src + ".png");
                j("#slideshow").css("left", "-500px");
                j("#slideshow").animate({"left": "40px", "opacity": "0.1"}, 500);
            })
        }//no sc
    );
});

我得到的错误是:

类型错误:表达式的结果 'imageAnswers.q1toQn[infoTableIndex]' [未定义] 不是对象。

提前感谢任何帮助。

.animate()的"complete"回调函数不会发送任何类型的索引或参数,因此您的i是未定义的。

如果它必须是顺序参数,则可以使用相同的infoTableIndex var,因此您将拥有:

imageAnswers.q1toQn[infoTableIndex].q1[infoTableIndex+1].src

希望这有帮助。干杯

PS:如果您更好地解释幻灯片的逻辑并举例说明,那就太好

相关内容

  • 没有找到相关文章

最新更新