只要您每页有 1 个轮播,接受的答案就可以正常工作。我有几个所以想我会添加到解决方案中:
基于使用标准引导轮播标记:
<div id="myCarousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="active item">…</div>
<div class="item">…</div>
<div class="item">…</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">‹</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">›</a>
</div>
您需要遍历轮播的每次出现,使用 $(this) 并获取其兄弟姐妹:
$('.carousel-inner').each(function() {
if ($(this).children('div').length === 1) $(this).siblings('.carousel-control, .carousel-indicators').hide();
});