gpt4 book ai didi

jquery - 如何编写JQuery回调函数

转载 作者:行者123 更新时间:2023-12-01 00:51:24 24 4
gpt4 key购买 nike

我的回调函数不起作用,我想在 configReq() 之后运行 test()

$(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

关于jquery - 如何编写JQuery回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23676845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com