Laravel:如何在删除按钮上添加确认?

时间:2019-12-13 12:00:56

标签: javascript html css laravel

我有以下代码:

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

我想在此删除按钮上添加确认。我该怎么办?

2 个答案:

答案 0 :(得分:2)

尝试使用此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>

答案 1 :(得分:1)

在提交表单之前致电事件onsubmit

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


<script>

  function deleteconform()
  {
  var x = confirm("Are you sure you want to delete?");
  if (x)
    return true;
  else
    return false;
  }

</script>