zoukankan      html  css  js  c++  java
  • 全选功能

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>收入计算器</title>
        <script   src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    </head>
    <body>

    <div class="row">
        <input type="checkbox" class="select-all"/>
        全选
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
    </div>

    <div class="row">
        <input type="checkbox" class="select-all"/>
        全选
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
    </div>

    <div class="row">
        <input type="checkbox" class="select-all"/>
        全选
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
        <input type="checkbox" class="single"/>
    </div>

    <script>

        $('.row').each(function () {
            // 一行一行的处理
            var row = $(this);

            // 全选功能,点击全选,选中所有
            row.find(".select-all").on("click", function(){
                // 控制本行的
                var checkboxes = row.find(".single");
                if($(this).is(":checked")){
                    checkboxes.prop("checked", true);
                }else{
                    checkboxes.prop("checked", false);
                }
            });

            // 点击单条,控制全选的状态
            row.find(".single").on("click", function(){
                // 单条选择后,获取没有选中的数量
                var unCheckedLength = row.find(".single:not(:checked)").length;
                if (unCheckedLength > 0) {
                    row.find(".select-all").prop("checked", false);
                } else {
                    row.find(".select-all").prop("checked", true);
                }
            });
        });

    </script>


    </body>
    </html>

  • 相关阅读:
    SqlServer事务语法及使用方法
    mysql解决自动断开8小时未曾用过的链接
    JIRA license申请和语言包下载
    String literal is not properly closed by
    android开发 NDK 动态链接多个第三方库(so)
    vim字符串替换
    VMware tools的用途及安装[跨系统文件拖拽]
    十大高明的Google搜索技巧
    安装ADT-20.0.3的时候产生org.eclipse.cdt.feature.group 0.0.0' but it could not be ..
    [Android NDK]修复/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 问题
  • 原文地址:https://www.cnblogs.com/xiaolinxi/p/5960389.html
Copyright © 2011-2022 走看看