jQuery 的效果顺序问题
我想 fadeOut
一个按钮,然后 fadeIn
Ajax 调用的响应。响应是一个新按钮。然而,以下代码的作用是淡出
第一个按钮,将其淡入,然后用新按钮替换它。我尝试了几种组合,但无法使其工作。我哪里出错了?
beforeSend: function()
{
$(this).fadeOut("slow");
},
success: function(response)
{
$(this).fadeIn("slow", function () {
$(this).parent().html(response);
});
}
I would like to fadeOut
a button, then fadeIn
the response an Ajax call. The response is a a new button. What the following code does, however, is fadeOut
the first button, fade it back in, then replace it with the new one. I tried a few combinations but could not get it to work. where did I go wrong?
beforeSend: function()
{
$(this).fadeOut("slow");
},
success: function(response)
{
$(this).fadeIn("slow", function () {
$(this).parent().html(response);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AJAX 调用中的
this
不再是前一个元素。您必须将其存储在 AJAX 调用之前的 var 中,例如:var button = $(this);
以及稍后的:
button.fadeOut();
等等。
this
inside an AJAX call is not the previous element anymore. You must store it in a var previous to the AJAX call, like:var button = $(this);
and later:
button.fadeOut();
and so on.
试试这个(注意淡出时输入错误的“show”):
Try this (note the mistyped "show" on fadeOut):
$(this).parent().html(response);
将有效消除this
。因此,将其更改为这个应该可以修复它:其中 #thething 是“this”的 id
编辑:也是 morgar 所说的。
$(this).parent().html(response);
would effectively eliminatethis
. So changing it to this should fix it:where #thething is the id of "this"
EDIT: also what morgar said.