2 回答
TA贡献1719条经验 获得超6个赞
这应该运行。确保在变量之前有一个 $。
(function() {
let array_img = [{
filename: "20140222_131314",
title: "img1",
},
{
filename: "20140712_203709",
title: "img2",
},
{
filename: "20190318_182928",
title: "img3"
},
{
filename: "20190422_181219",
title: "img4"
}
]
for (var i = 0; i < array_img.length; i++) {
$arr_img = array_img[i]
var $container = $(".images");
$container.append("<img src=/Photos/"+$arr_img[0]+".jpg/>");
}
}());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="images">
</div>
TA贡献1836条经验 获得超13个赞
我这样做了,现在它起作用了。我不知道这是否是最好的方法,但是...
(function (){
let array_img = [
{
filename:"20140222_131314.jpg",
title:"img1",
},
{
filename:"20140712_203709.jpg",
title:"img2",
},
{
filename:"20190318_182928.jpg",
title:"img3"
},
{
filename:"20190422_181219.jpg",
title:"img4"
}
]
for (var i = 0 ; i<array_img.length ; i++){
var arr_img = array_img = [i]
var $container = $(".images");
$container.append(arr_img[i+1],"<img src=photos/20140222_131314.jpg>")
$container.append(arr_img[i+1],"<img src=photos/20140712_203709.jpg>")
$container.append(arr_img[i+1],"<img src=photos/20190318_182928.jpg>")
$container.append(arr_img[i+1],"<img src=photos/20190422_181219.jpg>")
}
}());
添加回答
举报