• 永久的CheckBox(单选,全选/反选)!


    <html>
    <head>
        <title>选择</title>
        <script type="text/javascript" src="jquery-1.9.1.min.js"></script>
        <script type="text/javascript">
            $(function () {
                //单选组事件
                $("[name=chk]:checkbox").bind("click", function () {
                    if ($(this).attr("check")) {
                        $(this).removeAttr("check");
                    } else {
                        $(this).attr("check", true);
                    }
                })
    
                //全选或反选
                $("[name=chkName]:checkbox").click(function () {
                    if ($(this).attr("check")) {
                        $(this).removeAttr("check");
                        $("[name=chk]:checkbox").each(function () {
                            if ($(this).attr("check")) {
                                $(this).click();
                            };
                        });
                    } else {
                        $(this).attr("check", true);
                        $("[name=chk]:checkbox").each(function () {
                            if (!$(this).attr("check")) {
                                $(this).click();
                            };
                        });
                    }
    
                })
    
    
                $("#btnSub").click(function () {
                    var arr = [];
                    $("[name=chk]:checkbox").each(function () {
                        if ($(this).attr("check")) {
                            arr[arr.length] = $(this).attr("value");
                        }
                    })
                    alert(arr.join(","))
                })
            })
        </script>
    </head>
    <body>
        <div>
            <div>
                <span>
                    <input type="checkbox" id="chkAll" name="chkName" /></span>
            </div>
            <div>
                <input type="checkbox" id="Checkbox1" name="chk" value="1" />
                <input type="checkbox" id="Checkbox2" name="chk" value="2" />
                <input type="checkbox" id="Checkbox3" name="chk" value="3" />
                <input type="checkbox" id="Checkbox4" name="chk" value="4" />
            </div>
            <div>
                <input type="button" id="btnSub" value="提交" />
            </div>
        </div>
    </body>
    </html>
    在寂寞的日子里沉淀自己,在程序的日子里找到自己,我为梦想而坚持!

    如果对你有重要帮助,可以打赏一下!


  • 相关阅读:
    关押罪犯
    食物链
    归并排序(分治)
    并查集+路径压缩
    3的幂的和
    斐波那契数列的第N项
    0和5
    扔盘子
    线段相交
    回文字符串
  • 原文地址:https://www.cnblogs.com/Kummy/p/3163504.html
Copyright © 2020-2023  润新知