我的回调函数不起作用,我想在configReq()之后运行test() $(document).ready(function() { configReq($(this).attr('href'), test);});var test = function() { alert('hi');}; function configReq(thisUrl) { $('.progress').empty(); $('.p
$(document).ready(function() { configReq($(this).attr('href'), test); }); var test = function() { alert('hi'); }; function configReq(thisUrl) { $('.progress').empty(); $('.progress').append('<div class="progress-bar bg-success" style="width: 0%; display: block;"></div>'); }
请让我知道我哪里错了……?
像这样:$(document).ready(function() { configReq('Some item', test); }); function test() { console.log('Callback executed'); }; function configReq(thisUrl, callback) { console.log('Executing configReq'); if (callback) callback(); }
DEMO