在Laravel中,我希望我的删除按钮向其中添加一个确认选项:
{!!Form::open(['action'=>['PostsController@destroy', $posts->id], 'method'=> 'POST', 'class' => 'float-right'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class'=>'btn btn-danger'])}}
{!!Form::close()!!}
这是我要在其中添加确认弹出窗口的代码,该弹出窗口将要求您确认是否要删除。
答案 0 :(得分:0)
您可以将其替换为按钮。
{!!Form::open(['action'=>['PostsController@destroy', $posts->id], 'method'=> 'DELETE', 'class' => 'float-right'])!!}
{!! Form::button('Delete', ['type'=>'submit','value'=>'delete','class'=>'btn btn-danger','onclick'=>"return confirm('Are you sure?')"]) !!}
{!!Form::close()!!}
答案 1 :(得分:0)
这是我在项目中经常使用的代码段。这是默认的Web浏览器警报弹出窗口。它会创建一个隐藏的表单,并将要删除的属性的ID附加到该表单中。
<div class="pl-1">
<button type="button" name="button"
onclick="if(confirm('Are you sure you want to delete this?')){ $('form#delete-{{$obj->id}}').submit(); }"
class="btn btn-danger btn-sm">Delete
</button>
{!! Form::open(['method' => 'DELETE', 'route' => ['your_route.destroy',$obj->id], 'class' => 'hidden', 'id'=>"delete-".$obj->id]) !!}
{!! Form::close() !!}
</div>