【问题标题】:jQuery Cycle Plugin callback errorjQuery Cycle Plugin 回调错误
【发布时间】:2010-10-12 23:16:28
【问题描述】:

我无法在回调之前和之后使用 jQuery 的循环插件!

我不确定出了什么问题,我什至尝试使用文档中的示例代码。

代码如下:

$(document).ready(function(){

    function onBefore() { alert('before'); }

    $('.slideshow').cycle({
        before: 'onBefore'
    });
});

它会抛出一个错误:“错误:opts.before[0].apply is not a function”

在 chrome 中:“Uncaught TypeError: Object onBefore has no method 'apply'”

发生了什么!?

【问题讨论】:

    标签: javascript jquery callback cycle


    【解决方案1】:

    错误是因为.apply() 是函数上的方法,而不是字符串上的方法……而'onBefore' 是字符串。相反,不要使用字符串...使用直接引用,如下所示:

    $(document).ready(function(){    
        function onBefore() { alert('before'); }    
        $('.slideshow').cycle({
            before: onBefore
        });
    });
    

    或匿名函数:

    $(function(){
        $('.slideshow').cycle({
            before: function() { alert('before'); }
        });
    });
    

    【讨论】:

    • 天哪,菜鸟的错误。不敢相信我忽略了这一点。谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多