我刚开始使用Bootstrap4,正在网站中实现“轮播和下拉菜单”。但是,每当我在下拉菜单或轮播指示器上单击时,它们似乎都无法正常工作,它会在URL中添加ID并再次显示在页面顶部。以下是代码。
<div class="col-md-6">
<!-- http://w3widgets.com/responsive-slider/img/slide-2.jpg -->
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="http://w3widgets.com/responsive-slider/img/slide-2.jpg" alt="First slide">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="http://w3widgets.com/responsive-slider/img/slide-2.jpg" alt="Second slide">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="http://w3widgets.com/responsive-slider/img/slide-2.jpg" alt="Third slide">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
我已包含所有必需的CSS(bootstrap.min.css)
和JS(jQuery, Popper, bootstrap.min.js)
我不知道出了什么问题。它甚至也没有在控制台中显示任何类型的错误或警告。
答案 0 :(得分:1)
验证所有链接是否正确链接,并且将您定向到确切的文件位置或使用CDN
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.bundle.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="col-md-6">
<!-- http://w3widgets.com/responsive-slider/img/slide-2.jpg -->
<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="http://w3widgets.com/responsive-slider/img/slide-2.jpg" alt="First slide">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="http://w3widgets.com/responsive-slider/img/slide-2.jpg" alt="Second slide">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="http://w3widgets.com/responsive-slider/img/slide-2.jpg" alt="Third slide">
<div class="carousel-caption d-none d-md-block">
<h5>...</h5>
<p>...</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>