我有一个删除laravel应用程序中按钮的任务。
这是我的刀片文件删除按钮,
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/delete" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
和 TaskController 删除方法,
public function deleteOneProjectTask($projectId, $taskId)
{
DB::table('tasks')
->where('project_id', $projectId)
->where('id', $taskId)
->delete();
return redirect()->route('projects.show')->with('info', 'Task deleted successfully');
}
和任务删除路线,
Route::delete('projects/{projects}/tasks/{tasks}/delete', [
'uses' => '\App\Http\Controllers\TasksController@deleteOneProjectTask',
]);
现在我需要在删除任务之前单击删除按钮确认警报按摩。我该如何开发它?
答案 0 :(得分:5)
在锚标记上简单添加onclick
事件。
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/delete" class="editInline" onclick="return confirm('Are you sure to want to delete this record?')"><i class="glyphicon glyphicon-trash"></i></a>
示例:
<a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/delete" class="editInline" onclick="return confirm('Are you sure to want to delete this record?')">DELETE</a>
如果用户点击ok
,则只会执行您的href
操作。