jquery - 出现错误 : "$(...).carousel is not a function" although I've included JQuery, Bootstrap.min.css 和 Bootstrap.min.js

标签 jquery html twitter-bootstrap

这个问题之前已经被问过,我已经搜索过每个线程。不幸的是,它们都与我的情况无关。

我正在尝试制作一个多幻灯片轮播,按照此处的代码笔:https://codepen.io/anon/pen/OmZppE

我有,在我的<head> ,以下链接脚本/CSS

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

所以我假设我已经正确包含了 Jquery 和 Bootstrap(css 和 js)。然而当我执行这个脚本时

$('.multi-item-carousel').carousel({
  interval: false
});

// for every slide in carousel, copy the next slide's item in the slide.
// Do the same for the next, next item.
$('.multi-item-carousel .item').each(function(){
  var next = $(this).next();
  if (!next.length) {
    next = $(this).siblings(':first');
  }
  next.children(':first-child').clone().appendTo($(this));

  if (next.next().length>0) {
    next.next().children(':first-child').clone().appendTo($(this));
  } else {
    $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
  }
});

我收到错误:“Uncaught TypeError: $(...).carousel is not a function”

想法?

编辑:忘记了实际轮播的 html,忽略里面的 erb 代码。与提问无关。

<div class="carousel slide multi-item-carousel" id="theCarousel">
    <div class="carousel-inner">
    <% profile.ventures.each_with_index do |v, index| %>
    <% if index == 0 %>
        <div class="item active">
    <% else %>
        <div class="item">
    <% end %>
        <div class="col-xs-4">
        <%= link_to v do %>
           <div class="image-box">
                 <img src="http://placehold.it/600x450" class="thumbnail img-responsive">
                     <div class="image-box-caption">
                        <b>
                      <span class="image-box-text"><%= v.title %></span>
                    </b>
                      </div>
                      <div class="image-box-price">
                        <b><span class="image-box-text" style="color: white;">From $<%= v.price %></span></b>
                      </div>
            </div>
        <% end %>
        </div>
      </div>
     <% end %>
    </div>
    <a class="left carousel-control" href="#theCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
    <a class="right carousel-control" href="#theCarousel" data-slide="next"><i class="glyphicon glyphicon-chevron-right"></i></a>
  </div>

最佳答案

https://codepen.io/anon/pen/YVLQop

添加:

$(document).ready(function() {
  console.log( "ready!" );
});

关于jquery - 出现错误 : "$(...).carousel is not a function" although I've included JQuery, Bootstrap.min.css 和 Bootstrap.min.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43946085/

相关文章:

html - 可滚动和对齐的 CSS 表格

html - css3 Transition 变换让元素之间的空白

html - 在 css 中添加没有顶部边距的背景

html - Jasny bootstrap 手机不工作

css - 将自定义文本类添加到 Twitter Bootstrap 时保持响应能力

javascript - 更改自动滚动的 URL(pushstate?)

javascript - 将javascript json对象转换为字符串

javascript - 为什么 setAttribute 在 jQuery 的 attr 不起作用时起作用

javascript - Bootstrap 在 foreach 循环中崩溃

javascript - 无法与 javascript 中的 php echo 输出进行比较(jquery-post)