回调中的回调? [英] Callback in a callback?

查看:115
本文介绍了回调中的回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样写了一个回调(我相信它被称为)

I wrote a callback (I believe it's called) like this:

hugeFadeIn();

这是一个用于淡入某些内容的简单代码,这样我就不会一遍又一遍地重复使用相同的代码.

It's a simple code to fade in some content so that I don't reuse the same code over and over again.

然后我想在hugeFadeIn完成后执行一些代码... 所以我这样做了:

I then wanted to execute some code after hugeFadeIn finishes... So I did this:

hugeFadeIn(){
    //la la la
});

那是错误的,所以我这样做了:

And that was wrong, so I did this:

$(hugeFadeIn(){
    //la la la
});

我仍然遇到错误.我究竟做错了什么?谢谢大家:)

And I'm still getting errors. What am I doing wrong? Thanks everyone :)

修改 根据要求,hugeFadeIn函数的正文:

Edit As requested, the body of the hugeFadeIn function:

function hugeFadeIn() {
    $("#huge-loader").fadeIn("fast");
}

推荐答案

如果要在hugeFadeIn完成后运行某些内容,则需要传递回调.

If you want to run something after hugeFadeIn finishes, you need to pass your callback in.

function hugeFadeIn(after) {
    // whatever
    after();
}

(如果hugeFadeIn本身进行淡入并且不依赖于调用本身需要回调的内容.)

(If hugeFadeIn does the fade itself and doesn't rely on calling something that itself takes a callback.)

在OP编辑后进行编辑.

function hugeFadeIn(after) {
    $("#huge-loader").fadeIn("fast", after);
}

这篇关于回调中的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆