Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 插入带循环的img时出错_Javascript_Jquery_Loops_Nan - Fatal编程技术网

Javascript 插入带循环的img时出错

Javascript 插入带循环的img时出错,javascript,jquery,loops,nan,Javascript,Jquery,Loops,Nan,当我点击时,我想插入一个带有循环的多个img,图像的名称是“0.jpg”、“1.jpg”、“2.jpg”等等 为此,我使用包含all元素的数组: {name: '1', result:1, prefecture: "city", photo1:"0.jpg"}, 还有我的循环 $('.map area').click(function(){ index = $(this).index(); var dir = questions[index].name; var di

当我点击时,我想插入一个带有循环的多个img,图像的名称是“0.jpg”、“1.jpg”、“2.jpg”等等

为此,我使用包含all元素的数组:

{name: '1', result:1, prefecture: "city", photo1:"0.jpg"},
还有我的循环

$('.map area').click(function(){
    index = $(this).index();
    var dir =  questions[index].name;
    var div = document.getElementById("tooltip_img");
    var ul = document.getElementById("gallery");

        for (var i = 0; i < 5; i+= 1) {
            var img = document.createElement("IMG");
            var li = document.createElement('li');
            var a = document.createElement('a');
            a.setAttribute("class", "fancybox");
            a.setAttribute('rel', 'gallery1');
            a.setAttribute('id', i);
            img.setAttribute("src",questions[index].photo1);

            ul.appendChild(li)
            li.appendChild(a)
            a.appendChild(img)
            document.getElementById('container').appendChild(div);
        }
});
我有一个错误“net::ERR\u FILE\u NOT\u FOUND”

为什么我不能对通话图像使用索引

非常感谢

试试看

img.setAttribute("src",questions[index]["photo"+i]);
img.setAttribute("src",questions[index]["photo"+i]);