jQuery+ajax实现批量删除功能完整示例
本文实例讲述了jQuery+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="external nofollow" rel="stylesheet"> <link href="https://cdn.bootcss.com/layer/2.4/skin/layer.min.css" rel="external nofollow" 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>
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun测试上述代码运行效果。
更多关于jQuery相关内容可查看本站专题:《jquery中Ajax用法总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
相关文章
详谈jQuery操纵DOM元素属性 attr()和removeAtrr()方法
这篇文章主要详细介绍了jQuery操纵DOM元素属性 attr()和removeAtrr()方法,非常的全面细致,在这里推荐给小伙伴们。2015-01-01jQuery实现带延时功能的水平多级菜单效果【附demo源码下载】
这篇文章主要介绍了jQuery实现带延时功能的水平多级菜单效果,可实现响应鼠标事件延时展示菜单的功能,涉及jQuery结合时间函数动态操作页面元素属性的相关技巧,需要的朋友可以参考下2016-09-09jQuery getJSON()+.ashx 实现分页(改进版)
参考了上一篇Asp .net +jquery +.ashx 文件实现分页并作了改进:ashx返回json数据,减少传输数据量,html页面样式控制也比较灵活,感兴趣的朋友可以参考下哈2013-03-03jQuery Validate 验证,校验规则写在控件中的具体实例
本篇文章主要是对jQuery Validate 验证,校验规则写在控件中的具体实例进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助2014-02-02
最新评论