如何添加警报单击按钮Submit datatables yajra?拉拉韦尔 [英] how to add alert on-click button Submit datatables yajra ? Laravel
本文介绍了如何添加警报单击按钮Submit datatables yajra?拉拉韦尔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表数据,该表具有功能删除按钮. 此按钮已成功删除,但我需要添加警报单击确认才能删除:
I have a table data , this table have function delete button . this button is successfully delete but i need to add alert on-click confirmation to delete like this :
<a href="delete.php?id=<?=$row['id']; ?>"
onclick="return confirm('Anda yakin mau menghapus item ini ?')">[Hapus]</a>
但是我在服务器端使用了Datatales,我不知道该放在哪里onclick
but i using datatales serverside i dont know where i put this onclick
删除我的功能
public function indexDataTables_pns()
{
$pns = Data_pns::with('users','master_golongan','master_jabatan')->get();
return Datatables::of($pns)->addIndexColumn()
->addColumn('Nama', function ($pns) {
return '<a href="/pns/'.$pns->id.'" target="_blank">'.$pns->users->nama.'</a>';
})
->editColumn('edit', function ($pns) {
return '<a href="/edit_pns/'.$pns->id.'" target="_blank" class="btn btn-xs btn-success"><i class="glyphicon glyphicon-edit"></i></a>';
})
->editColumn('hapus', function ($pns) {
// THIS START HERE FOR DELETE FUNCTION
$c = csrf_field();
$m = method_field('DELETE');
return "<form action='/delete/$pns->id' method='POST'>
$c
$m
<button style='margin-left:10px; width: 30px;' type='submit'
class='btn btn-xs btn-danger delete'>
<i class='glyphicon glyphicon-remove-circle'></i>
</button>
</form>";
})
->rawColumns(['Nama' => 'Nama','hapus' => 'hapus','action' => 'action','edit'=>'edit'])
->make(true);
}
我可以在其中放置此onclick和此消息吗?
where i can put this onclick and this message ?
推荐答案
您可以在删除表单的按钮上使用它,例如
you can use it on your delete form's button like
<button style='margin-left:10px; width: 30px;' type='submit'
class='btn btn-xs btn-danger delete' onclick='return confirm("Anda yakin mau
menghapus item ini ?")'>
<i class='glyphicon glyphicon-remove-circle'></i>
</button>
或在您的表单中添加一个类,并在提交表单之前使用确认
or add a class to your form and use confirmation before submitting the form
<form action='/delete/$pns->id' method='POST' class='delete-form'>
现在将此脚本添加到您的视图文件中
now add this script in your view file
<script>
$('.delete-form').submit(function(event){
if(!confirm('Anda yakin mau menghapus item ini ?')){
event.preventDefault();
}
});
</script>
这篇关于如何添加警报单击按钮Submit datatables yajra?拉拉韦尔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文