Javascript 插入带循环的img时出错
当我点击时,我想插入一个带有循环的多个img,图像的名称是“0.jpg”、“1.jpg”、“2.jpg”等等 为此,我使用包含all元素的数组: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
{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]);