gpt4 book ai didi

javascript - 未捕获的 SweetAlert : Unexpected 2nd argument?

转载 作者:数据小太阳 更新时间:2023-10-29 03:49:04 29 4
gpt4 key购买 nike

我有 sweetalert 的问题,我想在按钮点击时显示确认框警报,但它不起作用

这是我的 JS 代码:

$(document).ready(function(){
$('[data-confirm]').on('click', function(e){
e.preventDefault(); //cancel default action

//Recuperate href value
var href = $(this).attr('href');


var message = $(this).data('confirm');

//pop up
swal({
title: "Are you sure ??",
text: message,
type: "warning",
showCancelButton: true,
cancelButtonText: "Cancel",
confirmButtonText: "confirm",
confirmButtonColor: "#DD6B55"},

function(isConfirm){
if(isConfirm) {
//if user clicks on "confirm",
//redirect user on delete page

window.location.href = href;
}
});
});
});

HTML:

<a data-confirm='Are you sure you want to delete this post ?' 
href="deletePost.php?id=<?= $Post->id ?>"><i class="fa fa-trash">
</i> Delete</a>

所有必需的文件都已导入。

最佳答案

您使用的代码来自最新版本 2。请继续阅读 Upgrading from 1.X.

你应该使用 promise跟踪用户交互。

更新代码

$(document).ready(function(){
$('[data-confirm]').on('click', function(e){
e.preventDefault(); //cancel default action

//Recuperate href value
var href = $(this).attr('href');
var message = $(this).data('confirm');

//pop up
swal({
title: "Are you sure ??",
text: message,
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal("Poof! Your imaginary file has been deleted!", {
icon: "success",
});
window.location.href = href;
} else {
swal("Your imaginary file is safe!");
}
});
});
});

注意事项

  • 类型已替换为图标选项。
  • 仅用按钮替换了 showCancelButton、CancelbuttonText、confirmButtonText 和 confirmButtonColor。
  • dangerMode:true 使确认按钮变为红色。

关于javascript - 未捕获的 SweetAlert : Unexpected 2nd argument?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46690732/

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