这是 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 元素(被单击的元素)。我怎样才能做到这一点?
最佳答案
获取对回调外部元素的引用,然后您可以在回调函数内使用它。
$('.class').click(function() {
var $el = $(this);
$(this).parent().next().slideToggle('slow', function() {
//use $el here
});
});
关于javascript - jQuery SlideToggle() 回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1245413/