尝试在删除之前要求确认,但其他提交会触发警报。如何将其限制为仅删除一个?
Trying to ask for confirmation prior to a delete, but alert is triggered by other submits. How can a restrict it to just the delete one?
这个按钮在table每行的最后一列。当您单击删除时,它会传递该特定行中项目的 ID。我只需要一种方法来测试它确实是被点击的删除按钮。
<form action="{{ route('weapons.destroy',$weapon->id) }}" id="delete"method="post">
<input type="hidden" name="_method" value="DELETE">
@csrf
<button id="btnDelete" class="button button";>D e l e t e</button>
</form>
</td>
</tr>
@endforeach
</table>
<script>
document.onsubmit=function(){
return confirm('Are you sure? This weapon will be permanently deleted.');
}
</script>
我相信这是一个简单的事情,我就是做不到。
你可以试试这个
@foreach ($weapons as $weapon)
<form class="delete" action="{{ route('weapons.destroy',$weapon->id) }}" method="POST">
<input type="hidden" name="_method" value="DELETE">
@csrf
<input type="submit" value="Delete">
</form>
@endforeach
<script>
$(".delete").on("submit", function(){
return confirm("Do you want to delete this item?");
});
</script>
我觉得用Modal实现删除确认会更好这个link很有用https://dev.to/kingsconsult/how-to-implement-delete-confirmation-in-laravel-8-7-6-with-modal-29c5
这个按钮在table每行的最后一列。当您单击删除时,它会传递该特定行中项目的 ID。我只需要一种方法来测试它确实是被点击的删除按钮。
<form action="{{ route('weapons.destroy',$weapon->id) }}" id="delete"method="post">
<input type="hidden" name="_method" value="DELETE">
@csrf
<button id="btnDelete" class="button button";>D e l e t e</button>
</form>
</td>
</tr>
@endforeach
</table>
<script>
document.onsubmit=function(){
return confirm('Are you sure? This weapon will be permanently deleted.');
}
</script>
我相信这是一个简单的事情,我就是做不到。
你可以试试这个
@foreach ($weapons as $weapon)
<form class="delete" action="{{ route('weapons.destroy',$weapon->id) }}" method="POST">
<input type="hidden" name="_method" value="DELETE">
@csrf
<input type="submit" value="Delete">
</form>
@endforeach
<script>
$(".delete").on("submit", function(){
return confirm("Do you want to delete this item?");
});
</script>
我觉得用Modal实现删除确认会更好这个link很有用https://dev.to/kingsconsult/how-to-implement-delete-confirmation-in-laravel-8-7-6-with-modal-29c5