Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用一个删除按钮删除选中的项目_Javascript_Php_Laravel - Fatal编程技术网

Javascript 如何使用一个删除按钮删除选中的项目

Javascript 如何使用一个删除按钮删除选中的项目,javascript,php,laravel,Javascript,Php,Laravel,我想制作一个删除按钮,删除选中的项目。表示删除所有选中项目的主按钮。我做了一个主复选框来检查所有的值。现在我想制作一个主按钮,删除选中的值。这是我的密码。我是新来的,请帮帮我。对不起,我的英语不好 @extends('footer') @extends('header') @section('body') <!DOCTYPE html> <html> <head> <title>Retrieve data|Std view</tit

我想制作一个删除按钮,删除选中的项目。表示删除所有选中项目的主按钮。我做了一个主复选框来检查所有的值。现在我想制作一个主按钮,删除选中的值。这是我的密码。我是新来的,请帮帮我。对不起,我的英语不好

@extends('footer')
@extends('header')

@section('body')
<!DOCTYPE html>
<html>
<head>
    <title>Retrieve data|Std view</title>
<link rel="stylesheet" type="text/css" href="{{ asset('public/css/style.css') }}">
<link rel="stylesheet" type="text/css" href="{{ asset('public/css/bootstrap.css') }}">
<script type="text/javascript" src="{{ asset('public/js/jQuery.js') }}"></script>
</head>
<body>

    @if(session()->has('success'))
    <div class="alert alert-success">
        <h3> {{ session()->get('success') }} </h3>
    </div>

    @endif 

<div class="container">
    <form action="" method="">
    <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">

    <h2 style="color: green">This Is View Form</h2>
    <a href = "insert" class="btn btn-primary">Add New</a>

//HERE IS MY MASTER DELETE BUTTON.
    <button type="submit" class="btn btn-danger"  >Delete</button><br><br>


    <table border="1" id="customers">
        <tr>
            <th>
//Here is my checkbox inside the loop.
    <input type="checkbox" id="master" onchange="checkall(this);"> All
            </th>
            <th>Name</th>
            <th>Email</th>
            <th>Update</th>
            <th>Delete</th>

        </tr>

        @foreach($data as $value)
        <tr>

            <td>
                <input type="checkbox" class="sub_chk_{{ $value->id }}"  value="{{ $value->id }}">
            </td>
            <td>{{ $value->name }}</td>
            <td>{{ $value->email }}</td>
<td><a href="edit/{{$value->id}}" class="btn btn-primary" >Edit</a></td>

//THIS DELETE BUTTON FOR SINGLE DELETE FUNCTION

<td><a href="delete/{{$value->id}}" onclick='ConfirmDelete()' class="btn btn-danger" >Delete</a></td>
        </tr>
        @endforeach
    </table>
    </form><br>

    {{ $data->links() }}

</div>  

</body>

</html>
@endsection

<script>

    function checkall(obj) {
        var selectedIds = [];
        if(obj.checked){
     $('input:checkbox').not(obj).prop('checked', 'checked');
     $("input:checkbox").each(function(){
        var $this = $(this);

    if($this.is(":checked")){
        selectedIds.push($this.attr("value"));
    console.log(selectedIds);
    }
     })
        }
        else{
     $('input:checkbox').prop('checked',false);
        }
 }

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


</script>
@extends('footer'))
@扩展('头')
@第节(“正文”)
检索数据|标准视图
@如果(session()->has('success'))
{{session()->get('success')}
@恩迪夫

首先,获取选中复选框的ID数组,然后在控制器中使用这些ID删除数据。对于第一个命名输入类型复选框(在foreach循环中),如下所示

<input type="checkbox" name="ids[]" class="sub_chk_{{ $value->id }}"  value="{{ $value->id }}">

就是这样。

首先,选中复选框获取ID数组,然后在控制器中使用这些ID删除数据。对于第一个命名输入类型复选框(在foreach循环中),如下所示

<input type="checkbox" name="ids[]" class="sub_chk_{{ $value->id }}"  value="{{ $value->id }}">

就是这样。

bro这是我的delete函数。我可以对它进行更改或创建新函数吗?为此,我的代码被赋予了bloewpublic函数destroy($id){$query=DB::table('student')->where('id',$id)->delete();return redirect()->route('std_view',$query with('success','delete Successfully!')}兄弟,我需要它作为主按钮,它位于循环之外。这是我的全部路由::get('insert','StudInsertController@insertform'); 路由::post('create','StudInsertController@insert'); 路由::get('view','StudInsertController@retrieve')->name('std_view');路由::get('edit/{id}','StudInsertController@showid'); 路由::post('post/{id}','StudInsertController@update')->name('update.student');路由::get('delete/{id}','StudInsertController@destroy');对不起,迟了答复。参数为$id的destroy函数仅用于删除特定行。因此,您需要创建另一个路由和函数,因为您需要两个单独的操作(一个用于删除单个特定行,另一个用于多个选定行)bro这是我的删除函数我可以对其进行更改或创建新函数吗?为此,我的代码被赋予bloewpublic函数destroy($id){$query=DB::table('student'))->where('id',$id)->delete();return redirect()->route('std_view',$query)->with('success','delete Successfully!');}BRO我需要它作为循环外部的主按钮这是我的全部路由route::get(‘插入’,’StudInsertController@insertform”);路由::post('create','StudInsertController@insert”);路由::get('view','StudInsertController@retrieve')->name('std_view');Route::get('edit/{id}','StudInsertController@showid');路由::post('post/{id}','StudInsertController@update')->name('update.student');Route::get('delete/{id}','StudInsertController@destroy“);很抱歉答复太晚。参数为$id的销毁函数仅用于删除特定行。因此,您需要创建另一个路由和函数,因为您需要两个单独的操作(一个用于删除单个特定行,另一个用于多个选定行)