[英]Order of jquery and javascript functions
我覺得我缺少明顯的東西,但是...
我所有的整潔jQuery函數都被迫從頁面正文中進行了特別緩慢的javascript API調用等待。 我想先運行jQuery,然后再運行api。 有沒有強制執行訂單的標准方法?
簡單的解決方法是,在setTimeout
語句中調用您的api
。
例:
$(document).ready(function(){
// beautiful jQuery code here
setTimeout(function(){
// terribly slow code here
}, 100);
});
通常,在繁重的代碼/ DOM操作上使用setTimeout
是一個好主意。 它將避免瀏覽器“凍結”。
好吧,如果您只想在JavaScript之前使用jquery,請執行以下操作:
function japi(){
japi.dosomething();
//Your api part here
}
$("#test").html("something");
//Lots of jquery here
japi();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.