【发布时间】:2021-06-30 11:58:16
【问题描述】:
Sweet-alert 在调用此 get_alert() 函数后未返回 true 或 false,请提出一些建议,我们如何才能做到这一点
function get_alert() {
$('#removeactive').on('click', function(e) {
e.preventDefault();
var message = $(this).data('confirm');
//pop up
swal({
title: "Are you sure ??",
text: message,
icon: "warning",
buttons: true,
dangerMode: true,
})
.then(function(isConfirm) {
console.log(isConfirm == true);
if (isConfirm == true) {
return true;
} else {
return false;
}
});
});
}
<button id="removeactive" data-confirm="Are you sure?" type="button">Click</button>
【问题讨论】:
-
我让你成为了你本来可以做到的minimal reproducible example
-
很可能是How do I return the response from an asynchronous call?,但我们可能需要更多的上下文 - 你是如何尝试使用这个函数的?
标签: javascript laravel sweetalert