gpt4 book ai didi

javascript - Sweet alert 正在覆盖循环中的先前警报

转载 作者:行者123 更新时间:2023-11-29 21:48:12 24 4
gpt4 key购买 nike

我在一个循环中调用了 sweet alert 函数但是 sweetalert 只显示了一次,我认为它覆盖了之前的 sweetalert,bcz 当我做简单的警报时它确实弹出了两次但是 sweet alert 只是给我看一次。我想要做的是在我点击确定或取消按钮时显示第二个或第三个警报,否则不要根据循环迭代显示第二个或下一个警报这是我的代码

$.each(data,function(index,elem){

NotificationPopUpIsApprove();

});

function NotificationPopUpIsApprove(){
swal({
title: "Are you sure?",
text: "The Task "+ task_name + " In Project " + project_name + "is Completed by " + uname ,
type: "warning",
confirmButtonText: "Approve!",
closeOnConfirm: false,
confirmButtonColor: "#44E753",
cancelButtonText: "Reasssign!",
showCancelButton: true,

},
function(isConfirm){
if (isConfirm === true) {
return true;
}else{
return false;
}
});

}

提前致谢..

最佳答案

$.each 是一个同步的 jQuery 方法,因此它不会等待触发此行为的 sweetalert 响应。

根据您的要求,希望对您有所帮助。

    var data = ['a', 'b', 'c'];
var task_name = "sweetalert";
var project_name = "Something";
var uname ="SweetAlert"

$(document).ready(function () {
NotificationCheck(data[0]);
});

function NotificationCheck(noti) {
is_last = (data.indexOf(noti) + 1 == data.length);

NotificationPopUpIsApprove(is_last, function (boool) {
if (boool) { // Do something with response from user
console.log(noti);
}

if (data.indexOf(noti) < (data.length)) { // Inject next element for user response
next = data.indexOf(noti) + 1;
NotificationCheck(data[next]);
}

});
}

function NotificationPopUpIsApprove(is_last, callback) {
swal({
title: "Are you sure?",
text: "The Task " + task_name + " In Project " + project_name + "is Completed by " + uname,
type: "warning",
confirmButtonText: "Approve!",
closeOnConfirm: false,
confirmButtonColor: "#44E753",
cancelButtonText: "Reasssign!",
showCancelButton: true,
},

function (isConfirm) {
if (is_last) { //Close SweetAlert box
swal.close();
}
callback(isConfirm); //Sends user's response
});

}

关于javascript - Sweet alert 正在覆盖循环中的先前警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30366694/

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