zoukankan      html  css  js  c++  java
  • 复选框操作

    js代码

    <script type="text/javascript">
            //全选/全不选
            function ChangeRoleStatus(id) {
                var status = $("#" + id).attr("checked");
                if (status == true || status == "checked") {
                    $("#" + id).attr("checked", "checked");
                    $("#" + id + "1 tr").each(function () {
                        $(this).find("input:checkbox").attr("checked", "checked");
                    })
                    //$("#" + id + "1 input[type=checkbox]").attr('checked', "checked");
                }
                else {
                    $("#" + id).removeAttr("checked");
                    $("#" + id + "1 tr").each(function () {
                        $(this).find("input:checkbox").removeAttr("checked");
                    })
                    //                $("#" + id + "1").find("input:checkbox").removeAttr("checked");
                }
            }
            //当子项选中一个时,父项选中;当子项没有选中一个时,父项取消选中
            function ChangeChildStatus(id) {
                //            var strs = id.spli('e');
                var status = $("#the" + id).attr("checked");
                var pid = $("#the" + id).attr("name");
    
                if (status == true || status == "checked") {
                    $("#the" + id).attr("checked", "checked");
                    var num = 0;
                    $("#" + pid + "1 tr").each(function () {
                        status = $(this).find("input:checkbox").attr("checked");
                        if (status == true || status == "checked") {
                            num += 1;
                        }
                    })
    
                    if (num == 1) {
                        $("#" + pid).attr("checked", "checked");
                    }
                }
                else {
                    $("#the" + id).removeAttr("checked");
                    var num1 = 0;
                    $("#" + pid + "1 tr").each(function () {
                        status = $(this).find("input:checkbox").attr("checked");
                        if (status != true && status != "checked") {
                            num1 += 1;
                        }
                    });
                    if (num1 == $("#" + pid + "1 tr").find("input:checkbox").length) {
                        $("#" + pid).removeAttr("checked");
                    }
    
                }
                //var pid = $("#" + id).parent().parent().parent().parent().attr("id");
                //alert(pid);
            }
            function SaveRoleProview() { 
                
            }
        </script>
    View Code

    页面代码

    <table class="table-bordered" style=" 50%">
                        <tr>
                            <th class="list_01">
                                <label>
                                    <input type="checkbox" id="1" onclick="ChangeRoleStatus(1)" />会员管理</label>
                            </th>
                            <td>
                                <table id="11">
                                        <tr class="contorl_table_tr">
                                            
                                            <td>
                                                <label>
                                                    <input type="checkbox" id="the1" name="1" onclick="ChangeChildStatus(1)" />会员列表</label>
                                            </td>
                                        </tr>
                                        <tr class="contorl_table_tr">
                                            
                                            <td>
                                                <label>
                                                    <input type="checkbox" id="the2" name="1" onclick="ChangeChildStatus(2)" />会员登记</label>
                                            </td>
                                        </tr>
                                        <tr class="contorl_table_tr">
                                            
                                            <td>
                                                <label>
                                                    <input type="checkbox" id="the3" name="1" onclick="ChangeChildStatus(3)" />会员等级</label>
                                            </td>
                                        </tr>
                                        <tr class="contorl_table_tr">
                                            
                                            <td>
                                                <label>
                                                    <input type="checkbox" id="the62" name="1" onclick="ChangeChildStatus(62)" />会员退货</label>
                                            </td>
                                        </tr>
                                        <tr class="contorl_table_tr">
                                            
                                            <td>
                                                <label>
                                                    <input type="checkbox" id="the65" name="1" onclick="ChangeChildStatus(65)" />会员充值</label>
                                            </td>
                                        </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
    View Code
  • 相关阅读:
    DjangoRestFramework学习二之序列化组件、视图组件 serializer modelserializer
    DjangoRestFramework 学习之restful规范 APIview 解析器组件 Postman等
    vue学习目录 vue初识 this指向问题 vue组件传值 过滤器 钩子函数 路由 全家桶 脚手架 vuecli element-ui axios bus
    vue框架的搭建 安装vue/cli 脚手架 安装node.js 安装cnpm
    Redis集合 安装 哨兵集群 安全配置 redis持久化
    linux vue uwsgi nginx 部署路飞学城 安装 vue
    爬虫第三部分综合案例
    creating server tcp listening socket 127.0.0.1:6379: bind No error
    爬虫第二部分
    外键为什么加上索引?
  • 原文地址:https://www.cnblogs.com/xibianriluo/p/5489271.html
Copyright © 2011-2022 走看看