3

I'm trying to make a simple jQuery accordion plugin and can't figure out why doesn't the 'this' keyword work as it should. Here's the code of the plugin:

(function( $ ){
$.fn.accrdn = function(userSettings) {
    var defaults = { 
        toggle: true
    };
    var options = $.extend({}, defaults, userSettings);
    var handle = this.find('.handle');//doesn't work!

    if (options.toggle) {
        handle.click(function(){
            $(this).next('.panel').slideToggle();
        });
    } else {
        handle.click(function(){
            $(this).next('.panel').slideUp();
        });
    };
};
})( jQuery );
4

1 回答 1

6

既然 OP 提供了代码使用的示例小提琴,问题是手风琴 div 的选择器,它应该是:

$(document).ready(function() {
    $('.accordion').accrdn({toggle:true, slideSpeed:500});
}); 

注意:选择器缺少.标识它是一个class选择器

这是修复

于 2013-04-03T15:18:18.907 回答