简体   繁体   中英

Why aren't my Bootstrap Controls working?

I'm trying to make a bootstrap carousel that contains 3 items at a time and has controls to switch to the next item. I created this carousel which does display the three items, the only problem is the controls aren't working when clicked, not quite sure what I'm missing.

I wrote a codepen with an example of my code here.

and my HTML below for quick referencing.

<div class="container">
  <div id="casesCarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner">
      <div class="row">
        <div class="col-md-4">
          <div class="carousel-item active">
            <div class="card card-body">
              <h1>0</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item active">
            <div class="card card-body">
              <h1>1</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item active">
            <div class="card card-body">
              <h1>2</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>3</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>4</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>5</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>6</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>7</h1>
            </div>
          </div>
        </div>
        <div class="col-md-4">
          <div class="carousel-item ">
            <div class="card card-body">
              <h1>8</h1>
            </div>
          </div>
        </div>
      </div>
    </div>
    <a class="carousel-control-prev" href="#casesCarousel" 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="#casesCarousel" role="button" data-slide="next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
 </div>

You are missing here a link to the java script that enables the work of caroussel.

Add the following code to the header of your page

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

Then try again after refreshing ctrl+F5. Caroussel does not work on pure HTML and CSS it requres js libraries from bootstrap

This example you find have an error in codepen;

bootstrap.min.js:6 Uncaught TypeError: Bootstrap's JavaScript requires jQuery. jQuery must @* be included before Bootstrap's JavaScript. at Object.jQueryDetection (bootstrap.min.js:6) at bootstrap.min.js:6 at bootstrap.min.js:6 at bootstrap.min.js:6 *@

the bootstrap JS source not added to files and become error when launch. please check your bootstrap JS existance and version to done this.

have not noticed row and column remove this. And visit bootstrap-carousel

and add jquery

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM