等到功能加载完毕

Dof*_*ofs 5 javascript jquery

当javascript函数完全加载时,如何在jQuery测试?我想使用一个gif,它显示加载,同时加载javascript函数,并在函数完全加载时隐藏它?

Cha*_*ant 9

$(function(){
    $("#loadingGIF").show();
    WaitForFunction();
});

function WaitForFunction()
{
    if (!$.isFunction(FUNCTION_TO_WAIT_ON_HERE)) {
       setTimeout( WaitForFunction, 100);
       return;
    }
    Function_Loaded();
}

function Function_Loaded(){
      $("#loadingGIF").hide();
}
Run Code Online (Sandbox Code Playgroud)

  • 这是一个循环和递归.它是一个条件循环(不是`for`或`while`),它正在调用自身,所以它是递归的.只是因为有一个延迟,不会使它更少递归,所有递归都有一个停止条件,否则会有一个无限循环. (3认同)
  • 我发布的代码中没有递归. (2认同)