我想在 codeigniter 中使用 sweetalert2 进行删除确认,但我不知道如何使它可以帮助我..?
这是 sweetalert2 脚本
<script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/promise-polyfill"></script>
<script src="<?php echo base_url(); ?>sweetalert2/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/sweetalert2/dist/sweetalert2.min.css">
<script type="text/javascript">
function hapus() {
event.preventDefault();
var form = event.target.form;
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
})}
</script>
这是删除按钮
<button onclick="hapus()" style="width:70px"type="button" class="btn btn-block btn-outline-danger"><?php echo anchor('postingan/hapus/'.$b->id,'Hapus'); ?></button>
这是控制器
function hapus($id){
$where = array('id' => $id);
$this->m_data->hapus_data($where,'blogs');
redirect('Postingan');
}
SMILET
蓝山帝景
元芳怎么了