开发者

adding a callback to a for loop

开发者 https://www.devze.com 2023-03-13 23:26 出处:网络
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.

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

精彩评论

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