Javascript .text()正在立即处理

Javascript .text()正在立即处理,javascript,jquery,Javascript,Jquery,我不知道该给什么标题,所以请我道歉,我只是好奇为什么在下面的代码中,文本在淡出之前就被更改了,即使我在淡出之后将其放置 $('form').submit(function(){ return false; }); $('button').on('click',function(){ $(this).addClass('busy'); $(this).parent().find('button').attr('disabled',true); $(this).par

我不知道该给什么标题,所以请我道歉,我只是好奇为什么在下面的代码中,文本在淡出之前就被更改了,即使我在淡出之后将其放置

$('form').submit(function(){
    return false;
});
$('button').on('click',function(){
    $(this).addClass('busy');
    $(this).parent().find('button').attr('disabled',true);
    $(this).parent().find("button:not('.busy')").fadeOut(500);
    $('p').text('Processing..').fadeIn(500).trigger('sfsfsf','wala');
});
$('p').on('sfsfsf',function(e,data){
    //this line below
    $(this).delay(1000).fadeOut(500).text('Complete!');
    $(this).fadeIn(500,function(){
        $(this).delay(500).fadeOut(500);
    });
});

为什么会这样?我该如何修复它?

因为在动画完成之前立即返回<代码>文本()然后立即得到处理。您应该更改
fadeOut()
回调中的文本

$(this).delay(1000).fadeOut(500, function () {
    $(this).text('Complete!');
});
不相关,但值得注意;您应该查看缓存
$(this)
的结果;你说得太多了

$('p').on('sfsfsf',function(e,data){
    var self = $(this);

    self.delay(1000).fadeOut(500, function () {
        self.text('Complete!');
    });

    self.fadeIn(500,function(){
        self.delay(500).fadeOut(500);
    });
});
因为在动画完成之前立即返回<代码>文本()然后立即得到处理。您应该更改
fadeOut()
回调中的文本

$(this).delay(1000).fadeOut(500, function () {
    $(this).text('Complete!');
});
不相关,但值得注意;您应该查看缓存
$(this)
的结果;你说得太多了

$('p').on('sfsfsf',function(e,data){
    var self = $(this);

    self.delay(1000).fadeOut(500, function () {
        self.text('Complete!');
    });

    self.fadeIn(500,function(){
        self.delay(500).fadeOut(500);
    });
});
尝试:

$(this).parent().find(“按钮:not('.busy')”).fadeOut(500,function(){ $('p').text('Processing..).fadeIn(500).trigger('sfsfsf','wala'); }); 尝试:

$(this).parent().find(“按钮:not('.busy')”).fadeOut(500,function(){ $('p').text('Processing..).fadeIn(500).trigger('sfsfsf','wala'); });
您需要更改淡入淡出的回调函数中的文本,就像在最后几行中一样:

$(this).fadeIn(500,function(){
        $(this).delay(500).fadeOut(500);
    });

否则将立即执行文本更改

您需要在淡入淡出的回调函数中更改文本,就像在最后几行中一样:

$(this).fadeIn(500,function(){
        $(this).delay(500).fadeOut(500);
    });

否则将立即执行文本更改

是,这是正确的。链中的所有函数都会立即执行。如果希望在动画之后执行某些操作,请使用所有动画都包含的回调参数

延迟只会延迟动画!它对不是动画的东西没有影响。因此:

$(this).fadeOut(500, function() { $(this).text('Complete!'); });

是的,没错。链中的所有函数都会立即执行。如果希望在动画之后执行某些操作,请使用所有动画都包含的回调参数

延迟只会延迟动画!它对不是动画的东西没有影响。因此:

$(this).fadeOut(500, function() { $(this).text('Complete!'); });

很好,现在我明白了。非常感谢。很好,现在我明白了。非常感谢。