【发布时间】:2018-06-01 20:59:35
【问题描述】:
我正在尝试使用来自 servlet 的一些图像制作一个轮播。我设法创建了轮播,但图像没有改变。始终是数组中的第一个图像。我确实从 din 文章中获得了代码:Bootstrap Carousel not working after adding items dynamically with jQuery。但我不允许对文章发表评论。 :(
<div class="container-fluid">
<div id='myContent'></div>
</div>
<p>${offer.toString()}</p>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function() {
wrapper = $('#myContent'),
carousel = $('<div/>', { id: "theCarousel3", "class": "carousel slide multi-item-carousel",
append:'<div class="carousel-inner"></div><a class="left carousel-control" href="#theCarousel3" data-slide="prev"></a><a class="right carousel-control" href="#theCarousel3"data-slide="next"></a>' }),
carouselInner =carousel.find('.carousel-inner').eq(0); wrapper.append(carousel);
carousel.carousel(); for (var i = 0; i <${houseImages.size()}; i++) {
imgElement = $('<div />', { "class": "item" + (i ? '' : ' active'),
append: $('<div/>', { "class": 'col-lg-4', append: $('<img/>', {
src:'data:image/jpg;base64,${houseImages.get(i)}', id: 'img' + i,
"class": 'img-responsive',
height: 300
})
})
})
carouselInner.append(imgElement);
}
})
</script>
更新:我使用 owlcarousel。
【问题讨论】:
-
如果你想让人们看到它,来吧伙伴格式化你的代码。至少接通prettier.io/playground。需要 2 秒。
-
对不起。现在好点了吗?
-
它在我看来是一样的。
标签: javascript html css jstl