本文介绍了传递$(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.
这是我现在的状态:
if($(this).hasClass('flag')) { $('someElement').slideUp(); $(this).slideDown(); }但是我想要的是slideDown在slideUp完成后运行,例如
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.
任何想法?
推荐答案>
Save the reference.
if($(this).hasClass('flag')) { var el = this; $('someElement').slideUp(function() { $(el).slideDown(); }); }更多推荐
传递$(this)到jQuery的回调?
发布评论