提交表单前确认警报 javascript

Confirm alert before submit form javascript

我想从 table 中删除一行。删除将通过单击锚标记进行,它将提交删除表单。但是在提交表单之前它会显示一个确认对话框。

<tr>
  <td>    
    <a href="javascript:void(0)" onclick="$(this).parent().find('form').submit().confirm("Are you sure?")">Delete</a>
    <form action="{{route('area.destroy',$row->id)}}" method="post">
      @method('DELETE')
      {{csrf_field()}}
    </form>
  </td>
</tr>

如何编写 JS/jQuery 代码?另外,如果我想使用 sweet alert 怎么办?

如果您能够修改代码,一个简单的内联解决方案可以是在表单内的提交按钮的 onclick 事件上发出警报。

<tr>
    <td>
        <form action="{{route('area.destroy',$row->id)}}" method="post">
            @method('DELETE')
            {{csrf_field()}}
            <button type="submit" onclick="return confirm('Are you sure?')"></button>
        </form>
    </td>
</tr>

您可以在 Laravel

中将 SweetAlert 与 AJAX 一起使用

SweetAlert : 检查文件: https://github.com/realrashid/sweet-alert

形成 Whosebug :

完整示例: https://youtu.be/bE8Err1twRw

试试这个:

Swal.fire({
   title: 'Yakin ingin menghapus penguji ?',
   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.isConfirmed) {
      $(`[data-penguji=${id_penguji}]`).parents('.raised.card').remove()
   }
})