开发者

adding a callback to a for loop

I am trying to get jQuery to remove an element after it as run through a cycle of other functions, but following code block executes the remove() before it has run any of the for loop.

function waves(){
    for(i=0;i<=10;i++){
            wave(x);
    };
    $(x).remo开发者_Python百科ve();
}


Add an if statement into your loop, that then calls your function.

function waves(){
    for(i=0;i<=10;i++){
            wave(x);
            if (i == 10) {
               callback();
            }
    };
}
function callback() {
    $(x).remove();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜