gpt4 book ai didi

jquery - 从 bootbox 确认回调函数获取值

转载 作者:行者123 更新时间:2023-12-01 03:39:04 25 4
gpt4 key购买 nike

console.log(r);什么也得不到。使用 bootbox 时如何将结果传递给 r 变量

function jconfirm(m){
bootbox.confirm({
message: m,
buttons: {
'cancel': {
label: 'No'
},
'confirm': {
label: 'Yes',
}
},
callback: function(result) {
return result;
}
});
}
jconfirm('Do you really ....', function(r){
console.log(r);
});

最佳答案

您可以尝试这种方法:

var jconfirm = function (message, callback) {
var options = {
message: message
};
options.buttons = {
cancel: {
label: "No",
className: "btn-default",
callback: function(result) {
callback(false);
}
},
main: {
label: "Yes",
className: "btn-primary",
callback: function (result) {
callback(true);
}
}
};
bootbox.dialog(options);
};


$('#delete').on('click', function (e, confirmed) {
if (!confirmed) {
e.preventDefault();
jconfirm("Do you really ....", function (r) {
console.log(r);
if (r) {
$('#delete').trigger('click', true);
}
});
}
});
$('#form').submit(function (e) {
//do your validation or whatever you need to do before submit
});

<强> JSFiddle

关于jquery - 从 bootbox 确认回调函数获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25843668/

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