Bootstrap 轮播图片滑块,我怎样才能让它工作?

Bootstrap Carousel Image slider, how can I make it works?

我需要这方面的帮助。这是我第一次使用 bootstrap,我已经厌烦了。我想制作 3 张图片,每次点击都会滑动和更改。我在 Boostrap 网站上找到了这段代码,但它不起作用。我正在使用他们的链接和脚本。

请帮帮我。对不起我的英语

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<div id = "slides" class = "carousel slide" data-ride = "carousel">
        <ul class = "carousel-indicators">
            <li data-target="#slides" data-slide-to="0" class ="active"></li>
            <li data-target="#slides" data-slide-to="1"></li>
            <li data-target="#slides" data-slide-to="2"></li>
        </ul>
        <div class = "carousel-inner">
            <div class = "carousel-item active">
                <img src = "img/img1.jpg">
                <div class = "carousel-caption">
                    <h1 class = "display-2">Test</h1>
                    <h3>Testing of the test</h3>
                    <button type = "button" class = "btn btn-outline-light btn-lg">tester</button>
                    <button type = "button" class = "btn btn-primary btn-lg">Jop</button>
                </div>
            </div>
            <div class = "carousel-item">
                <img src = "img/img2.jpg">
            </div>
            <div class = "carousel-item">
                <img src = "img/img3.jpg">
            </div>
        </div>
    </div>

您还没有添加下一个和预览按钮,请尝试使用此代码:

<!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" />
    <title>Document</title>
    <link
    href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
    rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
    crossorigin="anonymous"
    />
  </head>
  <body>

    <div id = "slides" class = "carousel slide" data-ride = "carousel" style="height: 100;">

      <div class = "carousel-inner">
          <div class = "carousel-item active">
            <img src = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" class="d-block w-100">
            <div class = "carousel-caption">
                  <h1 class = "display-2">Test</h1>
                  <h3>Testing of the test</h3>
                  <button type = "button" class = "btn btn-outline-light btn-lg">tester</button>
                  <button type = "button" class = "btn btn-primary btn-lg">Jop</button>
              </div>
          </div>
          <div class = "carousel-item">
              <img src = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" class="d-block w-100">
          </div>
          <div class = "carousel-item">
              <img src = "https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" class="d-block w-100">
          </div>
        </div>
        <button class="carousel-control-prev" type="button" data-bs-target="#slides" 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="#slides" data-bs-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="visually-hidden">Next</span>
        </button>
  </div>

    <script
      src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"
      integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p"
      crossorigin="anonymous"
    ></script>
    <script
      src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"
      integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF"
      crossorigin="anonymous"
    ></script>
  </body>
</html>

您添加的JS文件顺序错误(jquery必须在bootstrap文件之前! ) 而你使用了 Bootstrap 4 语法但调用了版本 5 资源

<html>
  <head>
    <title></title>
    <meta content="">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <style>
        #slides{ margin: 0 auto;}
        #slides, .carousel-inner, .carousel-item{
            height: 400px; width: 600px;
        }

    </style>
  </head>
  <body>

    <div id="slides" class="carousel slide" data-ride="carousel">
        <ul class="carousel-indicators">
            <li data-bs-target="#slides" data-bs-slide-to="0" class="active"></li>
            <li data-bs-target="#slides" data-bs-slide-to="1"></li>
            <li data-bs-target="#slides" data-bs-slide-to="2"></li>
        </ul>
        <div class="carousel-inner">
            <div class="carousel-item active">
                <img src="https://cdn.pixabay.com/photo/2020/02/11/16/25/manarola-4840080_960_720.jpg" class="d-block w-100">
                <div class="carousel-caption">
                    <h1 class="display-2">Test</h1>
                    <h3>Testing of the test</h3>
                    <button type="button" class="btn btn-outline-light btn-lg">tester</button>
                    <button type="button" class="btn btn-primary btn-lg">Jop</button>
                </div>
            </div>
            <div class="carousel-item">
                <img src="https://cdn.pixabay.com/photo/2020/03/24/20/40/manarola-4965450_960_720.jpg" class="d-block w-100">
            </div>
            <div class="carousel-item">
                <img src="https://cdn.pixabay.com/photo/2016/02/19/11/18/manarola-1209627_960_720.jpg" class="d-block w-100">
            </div>
        </div>

        <button class="carousel-control-prev" type="button" data-bs-target="#slides" 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="#slides" data-bs-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="visually-hidden">Next</span>
        </button>
    </div>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
  </body>
</html>