2010-08-11 264 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参数。