0

我试图将数组中的图像显示到页面上但遇到了困难

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

这是小提琴的链接

http://jsfiddle.net/d0okie0612/YTKHh/

4

1 回答 1

4

您没有在页面中插入任何内容。

一个解决方案是:

for (var p = 0; p < movieArray.length; p++) {
    $('body').append('<img src="'+movieArray[p].picture+'" title="'+movieArray[p].title+'">');
}

演示:http: //jsfiddle.net/YTkhh/2/

于 2013-03-26T18:32:43.367 回答