gpt4 book ai didi

javascript - Sweet Alert确认对话框在响应之前消失?

转载 作者:行者123 更新时间:2023-12-02 15:41:52 28 4
gpt4 key购买 nike

我的 Sweet Aler 确认对话框有问题。当我单击删除图标时,Sweet Alert 对话框显示不到一秒钟,然后消失并删除该元素。换句话说,我没有机会单击“删除”或“取消”。如何停止这个对话框让我选择一个选项?

<a href="insert.php?delete=20"><i class="fa fa-trash-o fa-2x pull-right trashbin"></i></a>
---
<script type="text/javascript">
document.querySelector('i.trashbin').onclick = function(event){

swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false

},

function(isConfirm){
if (isConfirm){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
};
</script>

最佳答案

尝试在后面添加 event.preventDefault();:

document.querySelector('i.trashbin').onclick = function(event) {

关于javascript - Sweet Alert确认对话框在响应之前消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32499625/

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