Datatables是一个jquery表插件。它是一个高度灵活的工具,可以向任何HTML表格添加高级交互功能。
最近有这样一种要求,要求批量删除表单。让我们通过示例代码向您介绍它。
1:单击所有选项的复选框,并选择以下列表中的所有复选框
2:再次单击所有选项的复选框,不要选择以下列表中的所有复选框
3:单次选择选择框
如图所示:
http://recordit.co/GLj5a5BWo9
简单的代码演示:
thead tr role=' row ' class=' heading ' th style=' width : 44.8889 px;'选择所有输入类型=' checkbox ' name=' keeper user group-checkable ' class=' group-checkable '数据集=' # sample _ 1。复选框/第/个报警日期/第=' a '名/第性别/第公司/第地点详情/第/tr
render :函数(数据、类型、行、元){ var content=' label style=' margin-left :32 px;类=“mt-checkbox mt-checkbox-single mt-checkbox-outline”;content=' input type=' checkbox ' name=' test ' class=' group-checkable ' value=' data ' '/';内容=“/label”;返回内容;}主要js零件代码:
/*批量删除*/$ ('# button1 ')。单击(function(){ if($(' input[name=' test ']: checked ')[0]==null){ alert('请选择要删除的消息');返回;} if(确认('确认删除?)){ var ids=新数组;$(' input[name=' test ']: checked ')。每个(函数(){ ids.push($(this))。val());n=$(这个)。父母(' tr ')。索引()1;//获取复选框行$(“table # datatable”)的顺序。find ('tr3360eq ('n '))。移除();});$.Ajax({ URL : base path ' SOS/delete alerts ',数据: 'ids=' ids ',类型: 'post ',数据类型: 'json ',成功:函数(数据){ datatable . reloaddable();} });}})摘要
以上是边肖推出的jQuery Datatables,实现了批量删除表的功能。希望对大家有帮助。如果你有任何问题,请给我留言,边肖会及时回复你。非常感谢您对我们网站的支持!