gpt4 book ai didi

javascript - 我看不到 Javascript 数组中的图像

转载 作者:行者123 更新时间:2023-12-03 07:20:44 25 4
gpt4 key购买 nike

我想从 Javascript 数组加载一些图像,但无法加载图像。有人可以看一下我的代码吗?

谢谢

var works = [
{
title: "First Project",
pic: "https://www.petfinder.com/wp-content/uploads/2012/09/Blog-Kitty-Cam-solo.jpg"
},
{
title: "Second Project",
pic: "http://www.animal-photography.com/thumbs/red_tabby_long_hair_kitten_~AP-0UJFTC-TH.jpg"
},
{
title: "Third Project",
pic: "http://www.animal-photography.com/thumbs/silver_tabby_kittens~AP-0JO6Y9-TH.jpg"
},
{
title: "Fourth Project",
pic: "http://www.animal-photography.com/thumbs/silver_tabby_kitten_looking_up~AP-0DLVMB-TH.jpg"
}
];
      //works
for(var i = 0; i < works.length; ++i) {
//script for array goes here
$('#work1').append('\
<div class="col-xs-6 col-md-6 col-md-3">\
<a href='#' class='work-img'>\
<img class="img-responsive" src="' + works[i].pic + '">\
<span class='info'><p class='proj-title'>Title:</p> src="' + works[i].title + '" </span>\
</a>\
</div>\
');//append closes

最佳答案

我更正了您代码中的一些内容:

See this fiddle

JS代码://有效

   for(var i = 0; i < works.length; ++i) {
//script for array goes here

$('#work1').append('<div class="col-xs-6 col-md-6 col-md-3">' +
'<a href="#" class="work-img">' +
'<img class="img-responsive" src="' + works[i].pic + '">' +
'<span class="info"><p class="proj-title">Title:</p>' + works[i].title + '</span>' +
'</a>' +
'</div>'
);//append closes
}

for 循环未关闭,元素的串联错误。每张图片的标题旁边的打印效果也不好。

关于javascript - 我看不到 Javascript 数组中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36227581/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com