【问题标题】:carousel not working - bootstrap轮播不工作 - 引导
【发布时间】:2016-11-03 13:52:35
【问题描述】:

我无法从第一张图片更改为第二张图片,它也不会在它们之间自动滑动。我究竟做错了什么?所以基本上我希望能够手动滑动以将图片更改为下一张,如果我不这样做,它会在一段时间后自动滑动。有人愿意看一下并告诉我这段代码有什么问题吗?同样由于某种原因,当我尝试先加载 jquery 时,控制台中出现错误提示:

bootstrap.min.js:6 未捕获的错误:Bootstrap 的 JavaScript 需要 jQuery(…)

我的代码:

<div class="container">
  <br>
  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      <li data-target="#myCarousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">

      <div class="item active">
        <img src="images/1.jpg" alt="Chania" width="460" height="345">
        <div class="carousel-caption">
          <h3>Chania</h3>
          <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
        </div>
      </div>

      <div class="item">
        <img src="images/2.jpeg" alt="Chania" width="460" height="345">
        <div class="carousel-caption">
          <h3>Chania</h3>
          <p>The atmosphere in Chania has a touch of Florence and Venice.</p>
        </div>
      </div>

      <div class="item">
        <img src="images/3.jpg" alt="Flower" width="460" height="345">
        <div class="carousel-caption">
          <h3>Flowers</h3>
          <p>Beatiful flowers in Kolymbari, Crete.</p>
        </div>
      </div>

      <div class="item">
        <img src="images/4.jpg" alt="Flower" width="460" height="345">
        <div class="carousel-caption">
          <h3>Flowers</h3>
          <p>Beatiful flowers in Kolymbari, Crete.</p>
        </div>
      </div>

    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>

【问题讨论】:

    标签: jquery twitter-bootstrap twitter-bootstrap-3


    【解决方案1】:

    您必须在添加引导 javascript 之前添加 jQuery。

    例如:

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <script
      src="https://code.jquery.com/jquery-2.2.4.min.js"
      integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
      crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    

    【讨论】:

    • 我做了但是我收到一条错误消息说它是未定义的&lt;link href="css/bootstrap.css" rel="stylesheet" type="text/css"&gt; &lt;link href="css/bootstrap-theme.css" rel="stylesheet" type="text/css" &lt;script type="text/javascript" src="js/jquery-3.1.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="js/bootstrap.min.js"&gt;&lt;/script&gt;
    猜你喜欢
    • 2012-03-10
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    相关资源
    最近更新 更多