zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    2020.2.14
    2020.2.13
    规划极限编程阅读笔记03
    学习进度——第十六周
    JSP跳转到Servlet的两种配置
    规划极限编程阅读笔记02
    规划极限编程阅读笔记01
    单词接龙
    学习进度——第十五周
    输入法评价
  • 原文地址:https://www.cnblogs.com/wjshan0808/p/3576178.html
Copyright © 2011-2022 走看看