JQuery下CheckBox全选全不选反选

时间:2014-03-03 01:58:08   收藏:0   阅读:516
bubuko.com,布布扣
    <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
bubuko.com,布布扣

JQuery下CheckBox全选全不选反选,布布扣,bubuko.com

原文:http://www.cnblogs.com/wjshan0808/p/3576178.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!