jQuery插件未定义选项



我有一个非常简单的jquery插件,我只是想读一下来自的选项,但无法弄清楚我做错了什么。什么时候我试着运行这个,我得到一个"options is undefined js error"。

这是我的代码:

(function($) { 
$.fn.extend({
headerSlideshow: function(){
    var defaults = {
            padding: 20,
            mouseOverColor : '#000000',
            mouseOutColor : '#ffffff'
        }
    var options =  $.extend(defaults, options);
},
header: function() {
    this.headerSlideshow(options);
    setInterval( "this.headerSlideshow(options)", 1000 );
}
});
}) (jQuery);  

很可能您必须在headerSlideshowheader函数中接受options参数:

function(options)

另外,不要将字符串传递给setInterval。这将使用eval。更好地传递一个函数:

header: function(options) {
    var element = this;
    this.headerSlideshow(options);
    setInterval(function() { element.headerSlideshow(options); }, 1000);
}

最新更新