Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获引用错误:未定义cycleImages_Javascript_Jquery - Fatal编程技术网

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

我在javascript中定义了函数cycleImages,但由于某些原因,它未定义,我的代码如下:

<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分,看来我不能投你一票。