我正在尝试在我的网站上安装Owl Carousel 2,这是第一次使用它,并且遵循所有的说明我仍然遇到了一些问题。
导入所有文件后:
<head>
<meta charset="utf-8">
<title>The badass man alive</title>
<!-- CSS -->
<link rel="stylesheet" href="assets/vendors/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/vendors/owl-carousel/assets/owl.carousel.css">
<!-- Javascript -->
<script src="assets/vendors/jQuery/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="assets/vendors/owl-carousel/owl.carousel.min.js" type="text/javascript"></script>
<script src="assets/js/script.js" type="text/javascript"></script>
添加演示javascript代码:
$(function() {
$('.owl-carousel').owlCarousel({
loop:true,
margin:10,
nav:true,
responsive:{
0:{
items:1
},
600:{
items:3
},
1000:{
items:5
}
}
});
});
尝试加载示例文件:
<div class="owl-carousel">
<div class="item"><h4>1</h4></div>
<div class="item"><h4>2</h4></div>
<div class="item"><h4>3</h4></div>
<div class="item"><h4>4</h4></div>
<div class="item"><h4>5</h4></div>
<div class="item"><h4>6</h4></div>
</div>
控制台返回:
jQuery.Deferred exception: a(...).find(...).andSelf is not a function TypeError: a(...).find(...).andSelf is not a function
at c.<anonymous> (file:///.../assets/vendors/owl-carousel/owl.carousel.min.js:2:7592)
at HTMLDivElement.e (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:2:3655)
at HTMLDivElement.dispatch (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:3:10315)
at HTMLDivElement.q.handle (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:3:8342)
at Object.trigger (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:4:5808)
at HTMLDivElement.<anonymous> (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:4:6318)
at Function.each (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:2:2815)
at r.fn.init.each (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:2:1003)
at r.fn.init.trigger (file:///.../assets/vendors/jQuery/jquery-3.1.1.min.js:4:6294)
at e.trigger (file:///.../assets/vendors/owl-carousel/owl.carousel.min.js:1:22366) undefined
Uncaught TypeError: a(...).find(...).andSelf is not a function(…)
我没有想到它为什么会返回这个错误。
答案 0 :(得分:1)
问题是旧版jQuery中没有andSelf功能。尝试将以下
添加到.js文件中$.fn.andSelf = function() {
return this.addBack.apply(this, arguments);
}
答案 1 :(得分:0)
这里的问题相同。我尝试使用旧版本的jQuery,它运行得很好。尝试使用旧版本的jQuery。
答案 2 :(得分:0)
.andSelf()在jQuery 1.8中已弃用,并在jQuery 3.0中删除。应该从jQuery 1.8开始使用.addBack()。
因此,对于快速而肮脏的修复,在 owl.caorusel.min.js 文件中,只需将“ andSelf ”替换为“ addBack < / strong>“,它会起作用。