我试图将数组中的图像显示在页面上但有困难
继承人js
var movieArray = [
{ title: "The Artist", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "A Better Life", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "Abduction", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "African Cats", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "Angel Crest", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "Arthur", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "Anonymous", picture: "http://cmclove.org/img/sw_off_off.png" },
{ title: "A Dangerous Method", picture: "http://cmclove.org/img/sw_off_off.png" },
];
for (var p in movieArray) {
console.log(p+ ':' +movieArray[p].title+ '|' +movieArray[p].picture);
}
这是一个指向小提琴的链接
答案 0 :(得分:4)
您没有在页面中插入任何内容。
解决方案是:
for (var p = 0; p < movieArray.length; p++) {
$('body').append('<img src="'+movieArray[p].picture+'" title="'+movieArray[p].title+'">');
}