【发布时间】:2018-04-16 10:19:25
【问题描述】:
我正在尝试使用 Ajax 从 json 文件中插入图像。这些图像将被 owl carousel 使用,但目前它只显示 json 文件中的最后一张图像。
这是我的代码:
html
<div class="content newFilms">
<h2 class="welcomeText">New Releases</h2>
<div class="owl-carousel owl-theme"></div>
</div>
js
$(document).ready(function() {
$.getJSON("data/owl.json",function(img){
$.each(img, function(index,img){
var $newImg = $(img.item);
$(".owl-carousel").append($newImg);
});
$(".owl-carousel").owlCarousel({
dots:true
});
});
});
json
[
{
"item":"<img src='images/slide1.jpg'/>",
"item":"<img src='images/slide2.jpg'/>",
"item":"<img src='images/slide3.jpg'/>"
}
]
【问题讨论】:
标签: jquery json ajax owl-carousel