ajax批量删除功能的实现源代码

效果展示:

完整代码如下:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <title>Ding Jianlong Html</title>
    <link  href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcss.com/layer/2.4/skin/layer.min.css" rel="stylesheet">
</head>
<body>
	<div class="container">
		<button class="btn btn-danger radius" onClick="batch_del()" style='margin:10px;'>批量删除</button>
	    <table style="width: 500px;" class="table table-striped table-hover table-bordered">
			<thead>
				<tr>
					<th scope='col' width="25"><input type="checkbox" value="" name="selectall"></th>
					<th scope='col' width="80">ID</th>
					<th scope='col' >标题</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td><input type="checkbox" value="10001"></td>
					<td>10001</td>
					<td >标题1</td>
				</tr>
				<tr>
					<td><input type="checkbox" value="10002"></td>
					<td>10002</td>
					<td >标题2</td>
				</tr>
				<tr>
					<td><input type="checkbox" value="10003"></td>
					<td>10003</td>
					<td >标题3</td>
				</tr>
				<tr>
					<td><input type="checkbox" value="10004"></td>
					<td>10004</td>
					<td >标题4</td>
				</tr>
				<tr>
					<td><input type="checkbox" value="10005"></td>
					<td>10005</td>
					<td >标题5</td>
				</tr>
			</tbody>
		</table>
	</div>

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdn.bootcss.com/layer/2.4/layer.min.js"></script>
<script>
	/*批量选中的效果*/
	$('input:checkbox[name="selectall"]').click(function(){
		if($(this).is(':checked')){
	        $('input:checkbox').each(function(){
	    		$(this).prop("checked",true);
			});
        }else{
           	$('input:checkbox').each(function(){
    			$(this).prop("checked",false);
			});
        }
	});

	/*获取ids,批量删除*/
    function batch_del() {
        var ids = '';
        $('input:checkbox').each(function(){
            if(this.checked == true){
                ids += this.value + ',';
            }
        });
        //layer.alert(ids);return;
        //下面的ajax根据自己的情况写
        layer.confirm('批量删除后不可恢复,谨慎操作!', {icon: 7, title: '警告'}, function (index) {
            $.ajax({
                type: 'POST',
                url: '你的url地址?ids=' + ids,
                data: {"1": "1"},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 200) {
                        $(obj).parents("tr").remove();
                        layer.msg(data.message, {icon: 1, time: 1000});
                    } else {
                        layer.msg(data.message, {icon: 2, time: 3000});
                    }

                },
                error: function (data) {
                    console.log(data.msg);
                },
            });
        });
    }
</script>
</body>
</html>

 

转载于:https://www.cnblogs.com/idjl/p/9610508.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值