61 lines
2.0 KiB
HTML
61 lines
2.0 KiB
HTML
{% load static %}
|
|
|
|
<div id="deleteModal" class="modal fade" tabindex="-1" role="dialog"
|
|
aria-labelledby="deleteModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="deleteModalLabel">提示
|
|
</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"
|
|
aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>此操作会删除当前数据,是否继续?</p>
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-light" data-bs-dismiss="modal">取消</button>
|
|
<button type="button" class="btn btn-primary" id="confirmDeleteBtn">删除</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
$(document).ready(function () {
|
|
var targetIdToDelete = null;
|
|
var deleteUrl = "{{ url.delete }}";
|
|
|
|
// 删除按钮点击事件,打开删除确认模态框
|
|
$('.delete-btn').on('click', function () {
|
|
targetIdToDelete = $(this).data('target_id');
|
|
$('#deleteModal').modal('show');
|
|
});
|
|
|
|
// 确认删除按钮点击事件
|
|
$('#confirmDeleteBtn').on('click', function () {
|
|
if (targetIdToDelete !== null) {
|
|
$.ajax({
|
|
type: 'GET',
|
|
url: deleteUrl,
|
|
data: {
|
|
'target_id': targetIdToDelete
|
|
},
|
|
success: function (response) {
|
|
alert('删除成功');
|
|
location.reload(); // 刷新页面
|
|
},
|
|
error: function (response) {
|
|
alert('删除失败,请重试。');
|
|
}
|
|
});
|
|
}
|
|
$('#deleteModal').modal('hide');
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|