简体   繁体   中英

Jquery / Bootstrap “Uncaught TypeError” when using Carousel

I've been trying to implement a simple image carousel into this website I'm making. It's very basic page right now and this is the order in which I'm linking the CSS's and javascripts

<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

I understand the importance of linking jquery first, which is what I've done. And this is how my carousel code looks.

<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
  <div class="carousel-item active">
    <img class="d-block w-100" src="img/badminton.jpg" alt="Badminton">
  </div>
  <div class="carousel-item">
    <img class="d-block w-100" src="img/football1.jpg" alt="Football">
  </div>
  <div class="carousel-item">
    <img class="d-block w-100" src="img/pool.jpg" alt="Pool">
  </div>
</div>

As you can see I've basically copied the one from their site just to get it working. My first image loads however trying to click the arrow to the next gives me the following error

Console log error of jquery / bootstrap conflict

I've looked online and there seems to be no consensus on which version of bootstrap should be used with which jquery. Any help would be appreciated, thanks.

The only change that I can recommend is removing the word "carousel" from the class names of the slide <divs> , like this:

<div class="item active">

And like this:

<div class="item">

This is for Bootstrap 3.3.7. I haven't reviewed 4.0 yet.

You need a new version of Bootstrap.Try my code.

  <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous"> <title>Document</title> </head> <body> <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="img/badminton.jpg" alt="Badminton"> </div> <div class="carousel-item"> <img class="d-block w-100" src="img/football1.jpg" alt="Football"> </div> <div class="carousel-item"> <img class="d-block w-100" src="img/pool.jpg" alt="Pool"> </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> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script> </body> </html> </body> </html> [with no error][1] 

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