jQuery 之ajax 批量删除

check 是全选全不选总复选框

checks是单个复选框

deletedAll是批量删除按钮 

 jquery代码

$('#check').click(function () {
        // 全选
        $('.checks').prop("checked",$(this).prop('checked'));
    })

    $('#deletedAll').click(function () {
        //创建数组
        var arr=[];
        $('.checks:checked').each(function () {
        //将选中的id值存入数组
            arr.push($(this).attr('value'));
        })
            $.ajax({
                url:"delete",  //路由
                type:'get',
                data:{id:arr},
                dataType:"json",
                success:function (e) {
                    if (e.code==666){
                        $('.checks:checked:checked').each(function () {
                            $(this).parents('tr').remove();
                        })
                    }
                    if (e.code==444){
                        alert('删除失败');
                    }
                }
            })
    })

HTML代码(数据是从数据库读取出来的)

 <div class="tablebox">
        <table class="table table-bordered table-hover">
            <thead>
            <tr>
               <th><input type="checkbox" id="check"></th>
                <th class="text-center">ID</th>
                <th>文章名称</th>
                <th>标记</th>
                <th>封面</th>
                <th>所属栏目</th>

                <th>作者</th>
                <th>状态</th>
                <th>赞</th>
                <th>点击</th>
                <th>排序</th>
                <th>发布日期</th>
                <th class="cell-small text-center"><i class="fa fa-bolt"></i> 操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($data as $val)
                <tr>
                    <td><input type="checkbox" class="checks" value="{{$val->id}}"></td>
                    <td class="cell-small text-center">{{$val->id}}</td>
                    <td><a href="javascript:void(0)">{{$val->title}}</a></td>
                    <td><span class="label label-danger">热</span></td>
                    <td><img src="/{{$val->img}}" alt="" style="width: 50px;height: 50px;"></td>
                    <td>{{$val->type}}</td>

                    <td>{{$val->author}}</td>
                    <td><input type="checkbox" name="yyy" lay-skin="switch" lay-text="ON|OFF" checked></td>
                    <td>{{$val->love}}</td>
                    <td>{{$val->clik}}</td>
                    <td>{{$val->sort}}</td>
                    <td>2021-3-20</td>
                    <td class="text-center">
                        <div class="btn-group">
                            <a href="{{url('curd/renew',$val->id)}}" class="btn btn-xs btn-info" data-toggle="tooltip"
                               data-placement="top" title="恢复数据"><i class="fa fa-info-circle"></i></a>
                        </div>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
    </div>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呀哈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值