zoukankan      html  css  js  c++  java
  • 永久的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>
    在寂寞的日子里沉淀自己,在程序的日子里找到自己,我为梦想而坚持!

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


  • 相关阅读:
    标准输入输出
    UNIX基础概念
    phpstrom设置php环境
    nginx+php+swoole安装记录
    MySQL索引
    生成器来解决大文件读取,大数据下载
    PHP调优
    PHP-FPM详解
    远程登录服务器配置
    HTTPS配置
  • 原文地址:https://www.cnblogs.com/Kummy/p/3163504.html
Copyright © 2011-2022 走看看