[英]Sweet Alert confirm dialog disappears before response?
I have a problem with Sweet Aler confirm dialog. 我对Sweet Aler确认对话框有疑问。 When I click the delete icon, the Sweet Alert dialog shows for less then a second and then disappears and delete the element.
当我单击删除图标时,Sweet Alert对话框显示的时间少于一秒钟,然后消失并删除该元素。 With other words I don't have the chance to click "Delete" or "Cancel".
换句话说,我没有机会单击“删除”或“取消”。 How to stop this dialog to let me choose an option?
如何停止此对话框让我选择一个选项?
<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>
Try adding event.preventDefault();
尝试添加
event.preventDefault();
after: 后:
document.querySelector('i.trashbin').onclick = function(event) {
You must replace the 'src' value from the 'a' tag with '#' and pass the 'delete=20' to the function. 您必须将'a'标记中的'src'值替换为'#',并将'delete = 20'传递给函数。 Then in that function if user clicks 'yes', redirect to the page specified with parameter that you passed to it.
然后在该函数中,如果用户单击“是”,则重定向到使用传递给它的参数指定的页面。 This solved my problem.
这解决了我的问题。 I hope helps you too.
希望对您也有帮助。
** Edited ** ** 编辑 **
<a href="#"><i class="fa fa-trash-o fa-2x pull-right trashbin"></i></a>
---
<script type="text/javascript">
document.querySelector('i.trashbin').onclick = function () {
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
}).then(function () {
swal({timer: 1000, title: "Deleted!", type: "success"});
setTimeout(function goAndDel() {
window.location.assign("insert.php?delete=20");
}, 1000);
});
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.