gpt4 book ai didi

javascript - Sweetalert2 Swal 火在弹出后消失。非常奇怪的错误

转载 作者:行者123 更新时间:2023-12-02 22:29:39 28 4
gpt4 key购买 nike

每当成功调用以下函数1时,Sweetalert对话框在打开后立即消失,并且位置reload()起作用。当 number_of_errors > 0 时,这是完全相同的代码,但在后一种情况下,sweetalert 保持打开状态。当成功为 1 时,如何使其保持打开状态

注意:作为 ajax 调用的结果,该函数是从另一个 sweetalert 函数调用的。另外,成功/错误图标不会显示:-(。HTML 中很好地引用了 css 和 js 文件

任何想法都非常受欢迎,请

提前致谢

function show_comment_result(
success,
number_of_errors,
error_messages,
action
) {
if (action == "new item") {
html_success = "The item was successfully added";
html_errorA =
'<p>We had an <font color="#ff0000">error</font>: <p>' +
'<p><font color="#ff0000">' +
error_messages +
'</font></p><b><a href="#" id="temp2" onclick="restart_entry(); ">Please Try Again</a></b>';
html_errorB =
'<p> <font color="#ff0000">UNKNOWN error occured</font>: <p><b><a href="#" id="temp2" onclick="restart_entry(); ">Please Try Again</a></b>';
} else if (action == "edit item") {
html_success = "The item was successfully edited";
html_errorA =
'<p>We had an <font color="#ff0000">error</font>: <p>' +
'<p><font color="#ff0000">' +
error_messages +
"</font></p>";
html_errorB = '<p> <font color="#ff0000">UNKNOWN error occured</font>';
} else if (action == "delete item") {
html_success = "The item was successfully deleted";
html_errorA =
'<p>We had an <font color="#ff0000">error</font>: <p>' +
'<p><font color="#ff0000">' +
error_messages +
"</font></p>";
html_errorB = '<p> <font color="#ff0000">UNKNOWN error occured</font>';
}

if (success == 1) {
Swal.fire({
type: "success",
title: "Success!",
icon: "success",
showConfirmButton: true,
html: html_success
});
if (action == "edit item" || action == "delete item") {
location.reload();
} else if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
//$('#HiddenForm')[0].reset();
if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
} else {
if (number_of_errors > 0) {
Swal.fire({
icon: "error",
titleText: "Ooops",
title: "Ooops...",
showConfirmButton: false,
html: html_errorA
});
} else {
Swal.fire({
icon: "error",
showConfirmButton: false,
titleText: "Ooops",
title: "Ooops...",
html: html_errorB
});
}
}
}

最佳答案

你可以这样做:

Swal.fire({
type: "success",
title: "Success!",
icon: "success",
showConfirmButton: true,
html: html_success
}).then(() => {
if (action == "edit item" || action == "delete item") {
location.reload();
} else if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
//$('#HiddenForm')[0].reset();
if (action == "new item") {
document.getElementById("HiddenForm").reset();
}
})

关于javascript - Sweetalert2 Swal 火在弹出后消失。非常奇怪的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58950870/

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