【问题标题】:Bootstrap 3: Full Slider not working. Uncaught TypeError: $(...).carousel is not a functionBootstrap 3:全滑块不工作。未捕获的类型错误:$(...).carousel 不是函数
【发布时间】:2017-01-29 15:36:50
【问题描述】:

我正在按照本网站上的模板创建主页:https://startbootstrap.com/template-overviews/full-slider/,但我无法使其正常工作。我可以加载所有图像,但是当我预览页面时,每个图像的标题重叠,按钮不起作用,图片显示不正确(我看到我的第一张图片,然后是页脚,然后是我的另外两张图片就在页脚之后)。

这是我的索引:

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="risorse/bootstrap-3.3.7-dist/css/bootstrap.min.css">
    <link href="risorse/stili/starter-template.css" rel="stylesheet">
    <link href="risorse/stili/full-slider.css" rel="stylesheet">
</head>

这是我在里面的滑块:

<!-- Full Page Image Background Carousel Header -->
    <header id="myCarousel" class="carousel slide">
        <!-- 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">
                <!-- Set the first background image using inline CSS below. -->
                <div class="fill" style="background-image:url('risorse/immagini/slider_1.jpg');"></div>
                    <h2>Chiesa San Marco - Baucina</h2>
                </div>
            </div>
            <div class="item">
                <!-- Set the second background image using inline CSS below. -->
                <div class="fill" style="background-image:url('risorse/immagini/slider_2.jpg');"></div>
                <div class="carousel-caption">
                    <h2>Mostra Expo Canina 2016 - Baucina</h2>
                </div>
            </div>
            <div class="item">
                <!-- Set the third background image using inline CSS below. -->
                <div class="fill" style="background-image:url('risorse/immagini/slider_3.jpg');"></div>
                <div class="carousel-caption">
                    <h2>Paesaggio Siciliano</h2>
                </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>
    </header>

在页脚之后,我有以下滑块的 jquery 函数:

<script src="risorse/js/jquery.js"></script>
    <script src="risorse/js/bootstrap.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>window.jQuery || document.write('<script src="risorse/jquery/jquery-3.1.1.min.js"><\/script>')</script>
    <script>
    $('.carousel').carousel({
        interval: 5000 //changes the speed
    })
    </script>

这是我的入门模板 CSS:

html {
  position: relative;
  height: 100%;
}

body {
  padding-top: 50px;
  /* Margin bottom by footer height */
  margin-bottom: 60px;
  height: 100%;
}
.starter-template {
  padding: 40px 15px;
  text-align: center;
}

.footer {
  position: relative;
  bottom: 0;
  width: 100%;
  /* Set the fixed height of the footer here */
  height: 60px;
  background-color: black;
}

.footer p {
    margin: 10px 0;
}

这是完整的滑块 CSS:

.carousel,
.item,
.active {
    height: 100%;
}

.carousel-inner {
    height: 100%;
}

/* Background images are set within the HTML using inline CSS, not here */

.fill {
    width: 100%;
    height: 100%;
    background-position: center;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -o-background-size: cover;
}

我检查了控制台,我得到了这个错误:Uncaught TypeError: $(...).carousel is not a function。我正在尝试解决方案,但似乎没有任何效果。

【问题讨论】:

  • 浏览器控制台有错误吗?
  • @MichaelCoker 实际上是的。我收到此错误:未捕获的 TypeError: $(...).carousel is not a function at index.html:97 (anonymous) @ index.html:97

标签: jquery html css carousel bootstrap-carousel


【解决方案1】:

尝试只加载一次 jquery 库。 在引导之前仅加载一个版本的 jquery,对于 Bootstrap 3,我认为对 jQuery 的依赖项设置为 1.9.0 或更高版本

【讨论】:

  • 所以,我当时尝试使用其中一个,但没有一个可以工作。你觉得我应该用哪一个?另外,我现在将尝试将它们加载到头部。
  • 我检查了控制台并收到以下错误:未捕获的 TypeError: $(...).carousel is not a function
  • 非常感谢,您非常有帮助!所以,现在我的页面只加载一次 jquery 并且它发生在我的函数在我的页脚之后加载之前。 jquery 的版本是 v1.11.1。我还注意到我的第二张图片的 div 没有关闭,所以我也修复了这个问题。
  • 您缺少第一张幻灯片中的 &lt;div class="carousel-caption"&gt;
猜你喜欢
  • 1970-01-01
  • 2021-10-15
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
  • 1970-01-01
  • 2016-01-22
  • 1970-01-01
  • 2018-09-25
相关资源
最近更新 更多