弘帝企业智能建站系统交流平台

 找回密码
 立即注册
查看: 927|回复: 0

CheckBox全选中与非选中状态的代码

[复制链接]
发表于 2022-4-4 21:54:01 | 显示全部楼层 |阅读模式
$("body").on("click","section .target .input .menu ul li [type=checkbox]",function(){
    //is(":checked"))来判断是否为选中状态,参考:http://wh.ac.cn/forum.php?mod=viewthread&tid=2374
    //半选中状态,参考:http://wh.ac.cn/forum.php?mod=viewthread&tid=2991
     if($(this).is(":checked")){       //方法一: 通过each来逐一处理
        $(this).closest("li").find("ul li [type=checkbox]").each(function(){
            $(this).prop('checked',true);
        });
    }else{
        //方法二:通过DOM统一处理,attr(),也是可以支持的
        $(this).closest("li").find("ul li [type=checkbox]").prop("checked",false);
    }
})




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|弘帝企业智能建站系统 ( 皖ICP备07503252号 )

GMT+8, 2024-5-22 00:16 , Processed in 0.056878 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表