gpt4 book ai didi

javascript - 如何使用 Sweet Alert 来确认 dropify.js 的图像删除?

转载 作者:行者123 更新时间:2023-12-03 01:43:18 29 4
gpt4 key购买 nike

我想在删除图像之前使用甜蜜的警报确认。但是,这不起作用。如果我使用 javascript 默认确认,它就可以工作。我尝试使用异步和等待,但没有帮助。我该如何修复/调试这个问题?

var pathURL = "file_path/";
var dropifyElements = {};
$('.dropify').each(function() {
dropifyElements[this.id] = true;
});
var drEvent = $('.dropify').dropify();

drEvent.on('dropify.beforeClear', function(event, element) {
id = event.target.id;
if(dropifyElements[id]) {
var x = false;
return swal({
title: "Are you sure?",
text: "You will not be able undo this operation!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel please!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm){
if (isConfirm) {
x = true;
} else {
swal({
title:"Cancelled",
text:"Delete Cancelled :)",
type:"error",
timer: 2000,
});
x = true;
}
});
return x;
//return confirm("Do you really want to delete this image?");
// return confirm("Do you really want to delete \"" + element.file.name + "\" ?");
}
});

最佳答案

好的,input 元素通过事件处理程序传递,因此如果用户确实想要删除它,您所要做的就是默认在处理程序上返回 false,那么如果用户点击 swal 实例上的确认按钮,您只需取消输入元素的值即可。我没有你的代码,但这应该可以。

var pathURL = "file_path/";
var dropifyElements = {};
$('.dropify').each(function() {
dropifyElements[this.id] = true;
});
var drEvent = $('.dropify').dropify();

drEvent.on('dropify.beforeClear', function(event, element) {
id = event.target.id;
if(dropifyElements[id]) {

swal({
title: "Are you sure?",
text: "You will not be able undo this operation!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel please!",
closeOnConfirm: false,
closeOnCancel: false
}, isConfirm => {
if (isConfirm) {
element.value = "";
} else {
swal({
title:"Cancelled",
text:"Delete Cancelled :)",
type:"error",
timer: 2000,
});
}
});

return false;

}
});

关于javascript - 如何使用 Sweet Alert 来确认 dropify.js 的图像删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50747418/

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