代码之家  ›  专栏  ›  技术社区  ›  lazysoundsystem

jquery和javascript函数的顺序

  •  2
  • lazysoundsystem  · 技术社区  · 14 年前

    我有种感觉我错过了一些明显的东西,但是。。。

    我所有整洁的jQuery函数都被页面主体中一个移动速度特别慢的javascript api调用强制等待。我希望先运行jQuery,然后再运行api。有没有一个标准的方法来执行命令?

    2 回复  |  直到 14 年前
        1
  •  4
  •   jAndy    14 年前

    简单的解决方法,请致电您的 api 在一个 setTimeout

    例子:

    $(document).ready(function(){
         // beautiful jQuery code here
         setTimeout(function(){
            // terribly slow code here
         }, 100);
    });
    

    一般来说,使用 大量的代码/DOM操作。它将避免浏览器“冻结”。

        2
  •  1
  •   nebkat    14 年前

    function japi(){
       japi.dosomething();
       //Your api part here
    }
    
    $("#test").html("something");
    //Lots of jquery here
    japi();