gpt4 book ai didi

javascript - 使用javascript删除记录

转载 作者:行者123 更新时间:2023-12-03 03:40:02 24 4
gpt4 key购买 nike

我有一个删除记录时确认警报的示例脚本。我正在尝试以某种动画的方式来做到这一点。但它无法正常工作。这是代码

删除按钮的 HTML 代码

<a href="delete1.php?id=1"><button class="btn btn-danger waves-effect waves-light btn-sm" id="danger-alert">Click me</button> </a>

脚本就像

 $('#danger-alert').click(function () {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "error",
showCancelButton: true,
cancelButtonClass: 'btn-default btn-md waves-effect',
confirmButtonClass: 'btn-danger btn-md waves-effect waves-light',
confirmButtonText: 'Danger!'
});
});

我不明白应该将delete1.php 文件放在脚本中的位置。

最佳答案

在回调函数中使用ajax调用delete1.php

 $('#danger-alert').click(function() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "error",
showCancelButton: true,
cancelButtonClass: 'btn-default btn-md waves-effect',
confirmButtonClass: 'btn-danger btn-md waves-effect waves-light',
confirmButtonText: 'Danger!',
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm) {
if(isConfirm) {
// do ajax
$.ajax({
url: 'delete1.php?id=1',
success: function(response) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
})
}
else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://t4t5.github.io/sweetalert/dist/sweetalert-dev.js"></script>
<link rel="stylesheet" href="http://t4t5.github.io/sweetalert/dist/sweetalert.css">
<button class="btn btn-danger waves-effect waves-light btn-sm" id="danger-alert">Click me</button>

关于javascript - 使用javascript删除记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45667414/

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