admin管理员组文章数量:1389768
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>
and this is the part of the 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()
and i am getting Uncaught TypeError: Cannot read property 'cycle' of undefined on
$target.data('carousel').pause().to(slideIndex).cycle()
this line.
I've just started to use js and if its a trivial question, sorry for that.
thanks advance.
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>
and this is the part of the 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()
and i am getting Uncaught TypeError: Cannot read property 'cycle' of undefined on
$target.data('carousel').pause().to(slideIndex).cycle()
this line.
I've just started to use js and if its a trivial question, sorry for that.
thanks advance.
Share Improve this question edited Dec 5, 2014 at 9:59 Ankit Srivastava 2561 silver badge8 bronze badges asked Dec 5, 2014 at 9:25 mstf dnmzmstf dnmz 211 silver badge2 bronze badges2 Answers
Reset to default 3This is because the code you posted, uses an external library called "jQuery"
its a Javascript file with lots of extension methods and other goodies. you probably didnt link it to your page.
you need to link jquery before all other scripts:
<script src="//code.jquery./jquery-1.11.0.min.js"></script>
or if you dont want to depend on external links, you can download this library to your website and use it locally. download jquery from HERE
You're assigning value to slideIndex instead of parison.
Instead of this.
if (slideIndex = $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
use this:
if (slideIndex == $this.attr('data-slide-to')) {
$target.data('carousel').pause().to(slideIndex).cycle()
}
本文标签: javascriptUncaught TypeError Cannot read property 39cycle39 of undefinedStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: Cannot read property 'cycle' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744594696a2614702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论