JQuery下CheckBox全选全不选反选

    <script src="JS/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        $(function () {
            $('[value=全选]').click(function () {
                $(':checkbox').attr("checked", "checked");
            });
            $('[value=全不选]').click(function () {
                $(':checkbox').removeAttr("checked");
            });
            $('[value=反选]').click(function () {
                ////1.
                //$(':checkbox').each(function () {
                //    $(this).attr("checked", !$(this).attr("checked"));
                //});
                //2.
                // $(':checkbox').each(function () {
                $(':checkbox').attr("checked", function () {
                    if ($(this).attr("checked"))
                        return false;
                    return true;
                });
                // });
            });
        });
    </script>
</head>
<body>
    <input type="button" value="全选" />
    <input type="button" value="反选" />
    <input type="button" value="全不选" /><br />
    <input type="checkbox" id="1" /><label for="1">1</label>
    <input type="checkbox" id="2" /><label for="2">2</label>
    <input type="checkbox" id="3" /><label for="3">3</label>
    <input type="checkbox" id="4" /><label for="4">4</label>
    <input type="checkbox" id="5" /><label for="5">5</label>
    <input type="checkbox" id="6" /><label for="6">6</label>
    <input type="checkbox" id="7" /><label for="7">7</label>
    <input type="checkbox" id="8" /><label for="8">8</label>
    <input type="checkbox" id="9" /><label for="9">9</label>

</body
原文地址:https://www.cnblogs.com/wjshan0808/p/3576178.html