jquery实现全选功能
2018-03-13 17:48
316 查看
<!--HTML部分:--><ul> <li><input type="checkbox" class="chk" id="checkAll"/><label for="checkAll">全选</label></li> <li><input type="checkbox" class="chk chk01"/>1</li> <li><input type="checkbox" class="chk chk01"/>2</li> <li><input type="checkbox" class="chk chk01"/>3</li> <li><input type="checkbox" class="chk chk01"/>4</li> <li><input type="checkbox" class="chk chk01"/>5</li></ul> <!--JS部分:-->
<script> $(document).on("click","#checkAll",function(){ $(".chk01").prop("checked",$(this).prop("checked"))//多选框的状态与全选框状态保持一致 }) $(".chk01").each(function(){ $(this).click(function(){ if(!$(this).prop("checked")){//多选框有一个未选中 全选变为未选中状态 $("#checkAll").prop("checked",false) }else if($(this).prop("checked")){ $(".chk01").each(function(index,ele){ if($(this).prop("checked")){ if(index == $(".chk01").length - 1){ $("#checkAll").prop("checked",true)//多选框全部选中 全选变为选中状态 } return true//each()跳过本次循环 }else{ return false//each()跳出循环 } }) } }) })</script>
<script> $(document).on("click","#checkAll",function(){ $(".chk01").prop("checked",$(this).prop("checked"))//多选框的状态与全选框状态保持一致 }) $(".chk01").each(function(){ $(this).click(function(){ if(!$(this).prop("checked")){//多选框有一个未选中 全选变为未选中状态 $("#checkAll").prop("checked",false) }else if($(this).prop("checked")){ $(".chk01").each(function(index,ele){ if($(this).prop("checked")){ if(index == $(".chk01").length - 1){ $("#checkAll").prop("checked",true)//多选框全部选中 全选变为选中状态 } return true//each()跳过本次循环 }else{ return false//each()跳出循环 } }) } }) })</script>
相关文章推荐
- JQuery实现全选,不选,反选功能
- 使用jquery实现全选,全不选,反选功能
- jQuery 实现 Checkbox 的全选、全不选和反向选择的功能
- jQuery实现的全选、反选和不选功能
- 基于jQuery实现复选框的全选 全不选 反选功能
- Jquery之实现全选反选功能
- jQuery实现全选反选功能
- jQuery实现的全选、反选和不选功能
- jquery实现checkbox全选功能,第二次点击【全选】按钮,页面无法勾选
- JQuery实现列表中复选框全选反选功能封装
- jQuery实现checkbox三种情况的全选功能
- jQuery实现的全选、反选和获取当前所有选中的值功能
- jQuery实现的全选、反选和不选功能
- jquery实现全选和全不选功能
- 基于jquery实现复选框全选,反选,全不选等功能
- jquery实现全选、全不选以及单选功能
- jQuery实现的全选、反选和不选功能
- JQuery 中 实现复选框全选/全不选/反选功能 案例
- jQuery实现表单全选、全不选以及反选的功能
- 使用JQuery实现全选、反选、添加和删除功能