传递$(this)到jQuery的回调?

编程入门 行业动态 更新时间:2024-10-23 13:32:07
本文介绍了传递$(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的回调?

本文发布于:2023-08-01 09:19:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267196.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:回调   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!