每页展示固定条数据的单选本页选择和全选的逻辑及js代码实现
来源:互联网 发布:淘宝怎么完成实名认证 编辑:程序博客网 时间:2024/05/30 21:59
逻辑:
1.全选:勾选时,本页勾选,单选全部勾选;取消勾选时,本页取消勾选,单选全部取消勾选
2.本页:勾选时,单选全部勾选,若勾选总数等于查询结果总数,全选也勾选;取消勾选时,本页全部取消勾选,全选取消勾选
3.单选:勾选时,判断已勾选条数,若等于本页总数,则本页勾选,若等于查询结果总数,则全选勾选;取消勾选时,本页取消勾选,全选取消勾选
变量:
1.selecteAll 全选标记
2.needContactsIds 已选择项
代码:
function bindCheckbox(){//翻页清除本页选择$('#selectAllByPage').removeAttr("checked");//列表总数totalRecords = Number($('#totalRecords').html());//翻页之后的全选if(selectAll){$('#selectAllByPage').prop("checked",true);$('#contactsView input').prop("checked",true);needContactsIds = ",";}//点击全选$('#selectAll').bind("click",function(){if($(this).is(":checked")){//选中selectAll = true;//全选标记$('#selectAllByPage').prop("checked",true);$('#contactsView input').prop("checked",true);}else{selectAll = false;$('#selectAllByPage').removeAttr("checked");$('#contactsView input').removeAttr("checked");}needContactsIds = ",";// 已选文件无记录});//点击分页全选$('#selectAllByPage').bind("click",function(){if($(this).is(":checked")){//选中$.each($('#contactsView input'),function(i,v){$(v).prop("checked",true);var key = $(v).attr("id");if(needContactsIds.indexOf(','+key+',') < 0){needContactsIds = needContactsIds + key + ',';}});var contactsArray = needContactsIds.split(",");if((contactsArray.length-2) == totalRecords){selectAll = true;$("#selectAll").prop("checked",true);needContactsIds = ",";}}else{$("#selectAll").removeAttr("checked");selectAll = false;$.each($('#contactsView input'),function(i,v){$(v).removeAttr("checked");var key = $(v).attr("id");if(needContactsIds.indexOf(','+ key +',')>-1){needContactsIds = needContactsIds.replace(','+key+',',',');}});}});//点击普通checkbox$('#contactsView input').bind("click",function(){if($(this).is(":checked")){var key = $(this).attr("id");if(needContactsIds.indexOf(','+key+',') < 0){needContactsIds = needContactsIds + key + ',';}var contactsArray = needContactsIds.split(",");//每页显示的数量if((contactsArray.length-2) == $('#contactsView input').length){$("#selectAllByPage").prop("checked",true);}if((contactsArray.length-2) == totalRecords){selectAll = true;$("#selectAll").prop("checked",true);$("#selectAllByPage").prop("checked",true);needContactsIds = ",";}}else{var key = $(this).attr("id");if(needContactsIds.indexOf(','+key+',') > -1){needContactsIds = needContactsIds.replace(','+key+',',',');}//其它已选中需添加到变量,避免全选再取消单选needContactsIds无内容$.each($('#contactsView input'),function(i,v){if($(this).is(":checked")){var key = $(this).attr("id");if(needContactsIds.indexOf(','+key+',') < 0){needContactsIds = needContactsIds + key + ',';}}});$("#selectAll").removeAttr("checked");$("#selectAllByPage").removeAttr("checked");selectAll = false;}});}
0 0
- 每页展示固定条数据的单选本页选择和全选的逻辑及js代码实现
- checkbox中全选和全不选及单选的实现
- ADF中改变table每页展示数据的行数
- 导航条固定及浮动的实现
- checkbox中全选和全不选的JS代码实现
- gird的底部分页工具栏下拉菜单,可以用下拉菜单选择每页显示多少条数据
- EXT 分页 每页显示N条数据的办法
- js全选和全不选的代码
- js实现简单的checkbox全选和取消全选效果
- JS实现checkbox的全选和取消全选
- Oracle创建视图实现获取当前数据所在的页数,这里以每页2条数据分页
- C# 使用js 实现GridView 的全选 /单选
- RecyclerView嵌套CheckBox实现单选全选反选操作每条Item添加分割线
- PPT VBA每页的标题进行音标及翻译展示在shapes(2)中
- 关于CheckBox全选以及反选还有单选,多选的逻辑实现
- 固定宽度中,展示图片和旋转图片展示的实现姿势
- JS左边select内容选择到右边select内容里面的js实现方法(可以多选和全选)
- js实现checkbox全选和全不选代码
- 分享12306全自动验证码识别提交,春运抢票准备时
- tinyxml使用
- 设置Weblogic以提高并发处理性能
- linux 线程学习1
- 分享八个开发技巧,助您薪水更上一层楼
- 每页展示固定条数据的单选本页选择和全选的逻辑及js代码实现
- java byte转换int
- update优化案例
- 利用java反射机制实现动态导出excel
- debian7配置apache+mysql+php
- Vision引擎中FXAA 后期处理器介绍
- 网络工程师之路
- 剑指offer系列源码-包含min函数的栈
- Android 读取 json 数据(遍历jsonarray和jsonboject)-FenGKun