Javascript 未捕获引用错误:未定义cycleImages
我在javascript中定义了函数cycleImages,但由于某些原因,它未定义,我的代码如下:Javascript 未捕获引用错误:未定义cycleImages,javascript,jquery,Javascript,Jquery,我在javascript中定义了函数cycleImages,但由于某些原因,它未定义,我的代码如下: <script> (function($) { function cycleImages(){ var $active = $('#cycler .active'); var $next = ($active.next().length > 0) ? $active.nex
<script>
(function($) {
function cycleImages(){
var $active = $('#cycler .active');
var $next = ($active.next().length > 0) ? $active.next() : $('#cycler img:first');
$next.css('z-index',2);
$active.fadeOut(1500,function(){
$active.css('z-index',1).show().removeClass('active');
$next.css('z-index',3).addClass('active');
});
}
$(document).ready(function(){
setInterval('cycleImages()', 7000);
})
})(jQuery);
</script>
(函数($){
函数cycleImages(){
var$active=$('#cycler.active');
var$next=($active.next().length>0)?$active.next():$(“#cycler img:first”);
$next.css('z-index',2);
$active.fadeOut(1500,函数(){
$active.css('z-index',1).show().removeClass('active');
$next.css('z-index',3).addClass('active');
});
}
$(文档).ready(函数(){
setInterval('cycleImages()',7000);
})
})(jQuery);
您实际上并没有捕获函数,只是传递了一个字符串:
setInterval('cycleImages()', 7000);
setInterval(cycleImages, 7000);
因此,当窗口尝试执行它时,它将计算该字符串并执行其中的代码。到那时,您已经超出了您的附件的范围,并且功能确实没有定义
您可以使用实际函数而不是字符串来捕获对函数的引用:
setInterval('cycleImages()', 7000);
setInterval(cycleImages, 7000);
谢谢你是最棒的,很抱歉,因为我还不到15分,看来我不能投你一票。