我有 3 个不同的 jQuery 函数,例如:
function step1() {
...
}
function step2() {
...
}
function step3() {
...
}
如果我这样称呼他们:
step1();
step2();
step3();
它们将同时执行。我怎样才能一一调用它们,所以step2();
在step1();
完成后step3();
调用,在完成后调用step2();
。
// 更多信息
Step1()
正在执行一个 json 并将详细信息附加到 html,Step2()
正在执行另一个 json 并将信息附加到由创建的 div 中Step1()
并Step3()
简单地隐藏加载动画。
// 函数
根据一些用户的要求,以下是功能:
jQuery.noConflict();
jQuery(document).ready(function($) {
var cardType = $.cookie('cardType');
var categoryID = $.cookie('categoryID');
function step1() {
$.getJSON('http://domain.com/benefits/active/all.json', function(data) {
$.each(data, function(i,item){
if (item.benefit_type_id == categoryID) {
content = '<li><a class="showDetails" data-offer-description="' + item.description + '" data-offer-period="' + item.begin_date + ' - ' + item.end_date + '"><div class="company" title="' + item.business_id + '"></div><div class="shortdescription">' + item.name + '</div></a></li>';
$(content).appendTo("#thelist");
}
});
step2();
});
} // function step1();
function step2() {
$('.company').each(function(i, item) {
var tempTitle = item.title;
$.getJSON('http://domain.com/businesses/from_list/' + tempTitle + '.json', function(data2) {
$.each(data2, function(i,item){
content = '<span>' + item.name + '</span>';
$(content).appendTo("div[title='" + tempTitle + "']");
});
step3();
});
});
} // function step2();
function step3() {
loaded();
$('#loading').delay(1000).fadeOut('slow', function() {
// Animation complete.
});
} // function step3();
step1();
});