1、问题:两个按钮无法使用
办法:
1、保证bootstrap.min.css 和bootstrap.min.js 文件都是一个版本。
我的版本
2、去Bootstrap5官网可以直接复制代码
Bootstrap5官网:Carousel · Bootstrap v5 中文文档 v5.1 | Bootstrap 中文网 (bootcss.com)
3、先引入bootstrap.min.css 。最后再引入bootstrap.min.js和jquery.min.js文件
代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Document</title>
<!-- 这里导入 bootstrap的 css文件-->
<link href="../node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<!-- 这里导入jquery的 js文件 bootstrap依赖于jquery所以需要先引入jquery文件-->
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<!-- 这里导入 bootstrap的 js文件 -->
<script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- 修改图片容器的大小-->
<style>
#carouselExampleIndicators {
width: 300px;
}
</style>
</head>
<body>
<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active"
aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1"
aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2"
aria-label="Slide 3"></button>
</div>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="img/jiangxuan_1.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="img/jiangxuan_2.jpg" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="img/jiangxuan_3.jpg" class="d-block w-100" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators"
data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators"
data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</body>
</html>