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
  • 相关阅读:
    js 常用方法
    Request.UrlReferrer
    批处理定时打开一个网页
    js基础知识总结:函数
    .NET DataTable转换为JSON格式的字符串
    .NET解析xml字符串,通过反射给实体类对象赋值,获取实体类数据列表
    .NET错误提示之:无法更新EntitySet“TableName”因为它有一个DefiningQuery
    python中安装web.py
    pycharm中运行flask项目安装flask
    jmeter--查看结果数中响应数据部分乱码
  • 原文地址:https://www.cnblogs.com/xibianriluo/p/5489271.html
Copyright © 2011-2022 走看看