简单批量删除结合CheckBox

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>show</title>
</head>
<body>
    <center>
    <table>
    <?php foreach ($data as $k => $v): ?>
    <tr>
      <td><input type="checkbox" class="checkbox" name="checkbox" value='<?=$v['id']?>'></td>
      <td><?=$v['title']?></td>
    </tr>
    <?php endforeach ?>
    </table>
        <input type="button" value="全选" id="all">
        <input type="button" value="全删" id="delAll">

    </center>
</body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script>
    $(document).on('click','#all',function()
    {
        $("input[name='checkbox']").each(function(){
            if($(this).prop("checked")){
                $(this).removeProp("checked");
            }else{
                $(this).prop("checked","checked");
            }
        })
    })
    $(document).on('click','#delAll',function()
    {
        var n_id = "";
        $(".checkbox").each(function(){
            if($(this).prop("checked")){
                n_id+=","+$(this).val();
            }
        })
        // $(".checkbox:checked").each(function(){
        //     n_id+=","+$(this).val();
        // })
        
        new_id = n_id.substr(1);

        $.ajax({
            type:"POST",
            url:"?r=csrf/del",
            data:"id="+new_id,
            success:function(msg){
                if(msg==1){
                    $(".checkbox").each(function(){
                        if($(this).prop("checked")){
                            $(this).parent().parent().remove();
                        }
                    })
                }
            }
        })
    })
</script>
</html>

原文地址:https://www.cnblogs.com/sensai-sun/p/6855412.html