未捕获的类型错误: 无法读取未定义的属性“循环”
Uncaught TypeError: Cannot read property 'cycle' of undefined
HTML Code:
<ol class="carousel-indicators">
<li data-target="#carousel-popular-devices" data-slide-to="0" class="pip"></li>
<li data-target="#carousel-popular-devices" data-slide-to="1" class="pip"></li>
<li data-target="#carousel-popular-devices" data-slide-to="2" class="pip active"></li>
<li class="all">
<a href="3" class="all">blabla</a>
</li>
</ol>
这是JavaScript的一部分:
var $this = $(this), href
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^'s]+$)/, '')) //strip for ie7
, options = $.extend({}, $target.data(), $this.data())
, slideIndex
$target.carousel(options)
if (slideIndex = $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
e.preventDefault()
并且我收到未捕获的类型错误:无法读取未定义的属性"循环"
$target.data('carousel').pause().to(slideIndex).cycle()
这一行。
我刚刚开始使用js,如果这是一个微不足道的问题,很抱歉。
谢谢提前。
这是因为您发布的代码使用了一个名为"jQuery"的外部库。
这是一个Javascript文件,有很多扩展方法和其他好东西。 您可能没有将其链接到您的页面。
您需要在所有其他脚本之前链接 jQuery:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
或者,如果您不想依赖外部链接,则可以将此库下载到您的网站并在本地使用。 从这里下载jQuery
您正在为幻灯片索引分配值而不是比较。
取而代之的是这个。
if (slideIndex = $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
使用这个:
if (slideIndex == $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
相关文章:
- TypeError:无法读取属性'推'未定义的JavaScript
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 未捕获的类型错误:无法读取属性'删除'的未定义
- AngularJS指令出错-无法读取属性'编译'的未定义
- 看到“;未捕获的类型错误:无法读取属性'weight'未定义的“;尽管按照字面上的指示
- angularjs无法读取未定义的属性then
- 无法读取属性'材料'未定义的Three.js
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- JavaScript承诺-无法读取属性'那么'的未定义
- 未捕获的类型错误:无法读取属性'中止'的未定义
- 角度推入数组给出:TypeError:无法读取属性'推'的未定义
- Javascript未捕获类型错误:无法读取属性'0'的未定义
- jQuery控制台错误:无法读取属性'top'的未定义
- TypeError:无法读取属性'findAll'的未定义
- 无法读取属性'errcap'未定义的jqgrid
- 无法读取未定义的属性“rid”
- 未捕获的类型错误: 无法读取未定义的属性“图像”
- 可以't读取'getHTML'未定义的Liferay CK Editor内容
- 在node.js中未定义读取属性错误