如何在Laravel中的我删除按钮上开发javascript按钮?

时间:2017-12-17 06:37:35

标签: javascript php laravel-5

我有一个删除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',
]);

现在我需要在删除任务之前单击删除按钮确认警报按摩。我该如何开发它?

1 个答案:

答案 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操作。