将 $(this) 传递给 jQuery 中的回调? [英] Passing $(this) to a callback in jQuery?
本文介绍了将 $(this) 传递给 jQuery 中的回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个效果想要一个接一个运行,但是我不知道如何将 $(this)
从第一个效果传递给回调.
I have two effects that I want to run one after another, but I can't work out how to pass $(this)
to the callback from the first effect.
这就是我目前所拥有的:
This is what I have at the moment:
if($(this).hasClass('flag')) {
$('someElement').slideUp();
$(this).slideDown();
}
但我想要的是在 SlideUp 完成后运行 slideDown,即.
But what I want is for the slideDown to run after the slideUp is complete, ie.
if($(this).hasClass('flag')) {
$('someElement').slideUp(function() {
$(this).slideDown();
});
}
除了 $(this)
到那个阶段现在指的是 someElement
而不是按计划工作.
Except $(this)
by that stage now refers to someElement
instead and so doesn't work as planned.
如何引用我原来的element.flag
.我尝试使用 $this = $(this)
但我想我一定是语法错误.
How do I refer to my original element.flag
. I tried using $this = $(this)
but I think I must have the syntax wrong.
有什么想法吗?
推荐答案
保存参考.
if($(this).hasClass('flag')) {
var el = this;
$('someElement').slideUp(function() {
$(el).slideDown();
});
}
这篇关于将 $(this) 传递给 jQuery 中的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文