• JS 全选、全不选、反选


    function checkReturn(obj) {
                    var objIds = obj.value;
                    //当没有选中某个子复选框时,checkboxall取消选中
                    if (!$("#subcheck").checked) {
                        $("#checkboxall").attr("checked", false);
                    }
                    // 获取subcheck的个数
                    var chsub = $("input[type='checkbox'][id='subcheck']").length;
                    // 获取选中的subcheck的个数 
                    var checkedsub = $("input[type='checkbox'][id='subcheck']:checked").length;
                    if (checkedsub == chsub) {
                        // 控制全选按钮的选中
                        $("#checkboxall").attr("checked", true); 
                    }
                }
                function funcCheckAll() {
                       // 判断全选按钮是否是已选中状态
                       // $("#checkboxall").prop("checked")说明已选中
                       // JQuery版本不同,if条件不同
                       if ($("#checkboxall").prop("checked")) {
                           // 将各个子单选按钮设为选中状态
                           $('input[name=ids]').attr('checked', 'checked');
                       } else { // 此时全选按钮起到反选作用
                            // 将选中状态改为非选中
                           $('input[name=ids]').removeAttr('checked');
                       }
                       // 将'全不选'按钮置为非选中状态
                       $('input[name=checkboxNotall]').removeAttr('checked');
                       // 将'反选'按钮置为非选中状态
                       $('input[name=checkboxInverse]').removeAttr('checked');
                }
                function funcCheckNotAll() {
                        // 将选中状态改为非选中
                       $('input[name=ids]').removeAttr('checked');
                       // 将'全选'按钮置为非选中状态
                       $('input[name=checkboxbutton]').removeAttr('checked');
                       // 将'反选'按钮置为非选中状态
                       $('input[name=checkboxInverse]').removeAttr('checked');
                }
                function funcCheckInverse() {
                    // 将'全选'按钮置为非选中状态
                       $('input[name=checkboxbutton]').removeAttr('checked');
                       // 将'全不选'按钮置为非选中状态
                       $('input[name=checkboxNotall]').removeAttr('checked');
                       // 获取所有子选框
                       var checkDelete = document.getElementsByName("ids");
                       for(var i=0; i<checkDelete.length; i++) {
                           // 判断全选按钮是否是已选中状态
                           if (checkDelete[i].type == "checkbox" && checkDelete[i].checked) {
                               // 将子选框设为非选中状态
                               checkDelete[i].checked = false;
                           } else { 
                               // 将子选框设为选中状态
                               checkDelete[i].checked = true;
                           }
                       }
                }
  • 相关阅读:
    Java读书笔记
    b_aw_旅游计划(树的中心变形)
    b_lc_秋叶收集器(分类讨论dp+滚动数组优化)
    b_lg_涂色(从小区间做起,讨论s[l]和s[r]的关系)
    c_lc_早餐组合(排序+双指针)
    c_aw_鱼塘钓鱼(大根堆)
    b_pat_栈(2*multiset+stack)
    c_pat_推荐系统(set模拟)
    b_lg_时态同步(后序遍历统计每棵子树的最大高度)
    b_lc_统计不开心的朋友(预处理+模拟)
  • 原文地址:https://www.cnblogs.com/yichenscc/p/10387333.html
Copyright © 2020-2023  润新知