轮播无法正常工作或没有响应

时间:2018-06-21 11:55:32

标签: html

我制作了一个轮播,它无法自动运行,也无法响应手动控制。 侧面的箭头不会响应。

我从W3Schools制作了旋转木马,我确定它可以使用,但是没有用。

您可以在Codepen上找到我的代码 我的代码:

    <head>
        <title>Bootstrap Example</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    </head>

    <body>

        <div class="container">
      <h2>Carousel Example</h2>  


            <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>
            </ol>

            <!-- Wrapper for slides -->
            <div class="carousel-inner">
              <div class="item active">
                <img src="https://www.derekprincearmenia.com/wp-content/uploads/2014/09/56699-nature-beauty-600x400.jpg" alt="Los Angeles" style="width:100%;">
              </div>

              <div class="item">
                <img src="http://globalmedicalco.com/photos/globalmedicalco/18/85311.png" alt="Chicago" style="width:100%;">
              </div>   

              <div class="item">
                <img src="http://stipsy.com/wp-content/uploads/2013/08/Hamilton-Pool-Nature-Preserve-9-600x400.jpg" alt="New york" style="width:100%;">
              </div>
            </div>

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

    </body>

2 个答案:

答案 0 :(得分:2)

这对我有用。希望能帮助到你。您需要在<head>标签中添加以下脚本:

<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>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/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>
</head>
<body>

<div class="container">
  <h2>Carousel Example</h2>  
  <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>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner">
      <div class="item active">
        <img src="https://www.derekprincearmenia.com/wp-content/uploads/2014/09/56699-nature-beauty-600x400.jpg" alt="Los Angeles" style="width:100%;">
      </div>

      <div class="item">
        <img src="http://globalmedicalco.com/photos/globalmedicalco/18/85311.png" alt="Chicago" style="width:100%;">
      </div>
    
      <div class="item">
        <img src="http://stipsy.com/wp-content/uploads/2013/08/Hamilton-Pool-Nature-Preserve-9-600x400.jpg" alt="New york" style="width:100%;">
      </div>
    </div>

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

</body>
</html>

答案 1 :(得分:1)

在您的<head></head>之间添加此内容:

<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>

这些是您需要的主要脚本,一个用于引导程序和jquery的脚本