bootstrap carousel不工作的图像

时间:2015-06-13 18:35:20

标签: twitter-bootstrap carousel

我正在尝试使用bootstrap制作旋转木马 以下是我的代码,但问题是它只显示一个图像。我添加了总共三张图片,但它只显示了其中一张图片。我也无法点击按钮的图标。我已经添加了上一个和下一个的按钮,但它们也没有在页面中看到。

<div id="mycarousel" class="carousel-slide">
    <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>
    <div class="carousel-inner">
        <div class="item active">
            <img src="1.jpg" alt="Fun" class="img-responsive">
        </div>
        <div class="item">
            <img src="2.jpg" alt="play" class="img-responsive">
        </div>
        <div class="item">
            <img src="3.jpg" alt="learn" class="img-responsive">
        </div>
    </div>
    <a class="carousel-control-left" href="mycarousel" data-slide="prev">
        <span class="icon-prev"></span>
    </a>
    <a class="carousel-control-right" href="mycarousel" data-slide="next">
        <span class="icon-next"></span>
    </a>    
</div>

我添加了js和jquery。

2 个答案:

答案 0 :(得分:0)

在第一个div处删除连字符:

class="carousel slide"

您似乎也错过了控件。这就是为什么你不能去下一张幻灯片。以下是链接here的引导文档提供的轮播的完整代码。                                                         

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    <div class="item">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    ...
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

答案 1 :(得分:0)

的Javascript

在脚本中包含此内容:

<script language="JavaScript" type="text/javascript">
  $(document).ready(function(){
    $('.carousel').carousel({
      interval: 2000
    })
  });    
</script>

这样你的代码应该是这样的:

<!-- jquery should be called first -->
<script language="JavaScript" type="text/javascript" src="scripts/jquery.js"></script>
<!-- javascript -->
<script language="JavaScript" type="text/javascript" src="scripts/bootstrap.min.js"></script>
  <!-- Carousel -->
<script language="JavaScript" type="text/javascript">
  $(document).ready(function(){
    $('.carousel').carousel({
      interval: 3000
    })
  });    
</script>