jQuery实现按钮的单选多选 反选全不选

jQuery拥有隐士迭代 随便添加checkebox也没关系

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jquery.mini.js"></script>
</head>
<body>
    <input type="checkbox" class="checkall">
    <input type="checkbox" class="checka">
    <input type="checkbox" class="checka">
    <input type="checkbox" class="checka">
    <input type="checkbox" class="checka">
    <script>
        $(function(){
            $(".checkall").change(function(){
                // console.log($(this).prop("checked"));
                $(this).siblings().prop("checked",$(this).prop("checked"));
            })
            $(".checka").change(function(){
                if($(".checka:checked").length==$(".checka").length){
                    $(".checkall").prop("checked",true)
                }else{
                    $(".checkall").prop("checked",false)
                }
            })
            
        })
    </script>
</body>
</html>

yds

おすすめ

転載: blog.csdn.net/weiyuyang250/article/details/120793561