尽管我已经包含了JQuery、Bootstrap.min.css和Bootstrap.min.js,但仍然出现错误:“$(...).carousel is not a function”

3

这个问题之前已经有人问过,我查看了所有的帖子。不幸的是,它们都与我的情况无关。

我正在尝试制作多幅幻灯片轮播图,参考这里的代码: 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));
  }
});

我看到了这个错误:"未捕获的类型错误:$(...).carousel不是一个函数"。
你有什么想法?
编辑:忘记了实际轮播的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>

可能是旧版本的jQuery库问题,也可能是https跨域问题。 - Alive to die - Anant
@AlivetoDie 我已经尝试使用你提供的链接,但即使清除缓存也没有任何改变。 - Joe
1个回答

0

我猜我甚至不需要.carousel函数。 - Joe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接