2010-08-11 213 views
0

如何運行第二個函數只有當第一個會在第一個時間完成?jquery,等待完成

$(document).ready(function() { 
$("#first").load("first.php?id="+ Math.random()); 
$("#second").load("second.php?id="+ Math.random()); 
}); 

回答

2

load()帶有一個回調參數:

$(document).ready(function() { 
$("#first").load("first.php?id="+ Math.random(), {}, function() { 
    $("#second").load("second.php?id="+ Math.random()); 
}); 
}); 

{}是用於傳遞一個空對象到data參數。