3

这是 jQuery slideToggle 函数:

$('.class').click(function() {
    $(this).parent().next().slideToggle('slow', function() {
        // how can I access $('.class') that was clicked on
        // $(this) returns the $(this).parent().next() which is the element
        // that is currently being toggled/slided
    });
});

在回调函数中,我需要访问当前的 .class 元素(被点击的那个)。我怎样才能做到这一点?

4

1 回答 1

19

在回调外部引用元素,然后可以在回调函数内部使用它。

$('.class').click(function() {
    var $el = $(this);
    $(this).parent().next().slideToggle('slow', function() {
         //use $el here
    });
});
于 2009-08-07T15:28:27.247 回答