我有以下代码:

{{ Form::open(['method'=>'DELETE','url'=>['/back/roles/delete/'.$row->id],'style'=>'display:inline' ]) }}
{{ Form::submit('Delete',['class'=>'btn btn-danger' ]) }}
{{ Form::close() }}

我想在这个删除按钮上添加确认。我怎样才能做到这一点?

最佳答案

试试这个使用 onsubmit

'onsubmit' => 'return confirmDelete()'

像这样写
{{ Form::open([
    'method'   => 'DELETE',
    'url'      => ['/back/roles/delete/' . $row->id],
    'style'    => 'display:inline',
    'onsubmit' => 'return confirmDelete()'
]) }}

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
    function confirmDelete(){

     var conform = confirm("Are you sure you want to delete?");
     if (conform)
       return true;
     else
       return false;
     }
    }
</script>

关于javascript - Laravel : How to add a confirmation on delete button?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59322214/

10-15 06:00