jQuery 的效果顺序问题

发布于 2024-11-06 11:21:13 字数 476 浏览 3 评论 0原文

我想 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把时间冻结 2024-11-13 11:21:13

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.

飘过的浮云 2024-11-13 11:21:13

试试这个(注意淡出时输入错误的“show”):

beforeSend: function()
{
    $(this).fadeOut("slow");
},

success: function(response)
{
    $(this).parent().html(response);
    $(this).stop().fadeIn("slow");
}

Try this (note the mistyped "show" on fadeOut):

beforeSend: function()
{
    $(this).fadeOut("slow");
},

success: function(response)
{
    $(this).parent().html(response);
    $(this).stop().fadeIn("slow");
}
ι不睡觉的鱼゛ 2024-11-13 11:21:13

$(this).parent().html(response); 将有效消除 this。因此,将其更改为这个应该可以修复它:

$(this).parent().html(response);
$("#thething").stop().fadeIn("slow");

其中 #thething 是“this”的 id

编辑:也是 morgar 所说的。

$(this).parent().html(response); would effectively eliminate this. So changing it to this should fix it:

$(this).parent().html(response);
$("#thething").stop().fadeIn("slow");

where #thething is the id of "this"

EDIT: also what morgar said.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文