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>
    在寂寞的日子里沉淀自己,在程序的日子里找到自己,我为梦想而坚持!

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


  • 相关阅读:
    matplotlib-形状
    matplotlib-区域填充
    C++文件操作
    画数学公式
    文字
    画注释
    Doubango简介-sip
    boost的asio接收单路大数据量udp包的方法
    Boost.Asio基本原理(CSDN也有Markdown了,好开森)
    boot asio 非阻塞同步编程---非阻塞的accept和receive。
  • 原文地址:https://www.cnblogs.com/Kummy/p/3163504.html
Copyright © 2011-2022 走看看