Bootstrap Carousel不起作用

时间:2014-12-14 07:44:25

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

旋转木马的按钮都没有响应,每次点击都没有做任何事情。旋转木马的第一张图片出现了,但我无法继续前进到另一张图片。这是一个截图

enter image description here

这是HTML代码http://pastebin.com/cmtkH9vA 请帮我解决这个问题,因为我想尽可能快地完成旋转木马。谢谢。

2 个答案:

答案 0 :(得分:2)

当我运行你的代码时,它会在Firebug中出现以下错误:

Error: Bootstrap's JavaScript requires jQuery

这是因为jQuery未在您的代码中正确加载。

您可以(快速)通过将http://或https://添加到jQuery网址来解决此问题。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

答案 1 :(得分:0)

对于使用Bootstrap Carousel你的HTML应该是这样的,并且记住bootstrap.min.js使用jQuery,所以你应该首先添加jQuery的引用:

<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.min.css"></script>
<div id="homeCarousel" class="carousel slide">
  <!-- Menu -->
  <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>
  </ol>

  <!-- Items -->
  <div class="carousel-inner">

      <!-- Item 1 -->
    <div class="item active">
        <img src="http://lorempixel.com/1500/600/abstract/1"/>
      <div class="container">
        <div class="carousel-caption">
          <h1>Bootstrap 3 Carousel Layout</h1>
          <p>This is an example layout with carousel that uses the Bootstrap 3 styles.</p>
          <p><a class="btn btn-lg btn-primary" href="http://getbootstrap.com">Learn More</a>
        </p></div>
      </div>
    </div>

      <!-- Item 2 -->
    <div class="item">
        <img src="http://lorempixel.com/1500/600/abstract/2"/>
      <div class="container">
        <div class="carousel-caption">
          <h1>Changes to the Grid</h1>
          <p>Bootstrap 3 still features a 12-column grid, but many of the CSS class names have completely changed.</p>
          <p><a class="btn btn-large btn-primary" href="#">Learn more</a></p>
        </div>
      </div>
    </div>

      <!-- Item 3 -->
    <div class="item">
        <img src="http://lorempixel.com/1500/600/abstract/3" />
      <div class="container">
        <div class="carousel-caption">
          <h1>Percentage-based sizing</h1>
          <p>With "mobile-first" there is now only one percentage-based grid.</p>
          <p><a class="btn btn-large btn-primary" href="#">Browse gallery</a></p>
        </div>
      </div>
    </div>
  </div>
  <!-- Controls -->
  <a class="left carousel-control" href="#myCarousel" data-slide="prev">
    <span class="icon-prev"></span>
  </a>
  <a class="right carousel-control" href="#myCarousel" data-slide="next">
    <span class="icon-next"></span>
  </a>  
</div>


 <script>
        $(function () {
    $('#homeCarousel').carousel({
        interval:2000,
        pause: "false"
    });
    });
  </script>

以下是fiddle