给角色添加权限和修改权限

#给已有的角色添加新的权限
遍历角色权限以及对需要添加的权限进行处理
为了格式所以并没有使用无限极分类查询,而用了三层遍历

<div class="cnt">
  {foreach $parent as $value}         
    <table class="data-form" width="60%" border="0" cellspacing="0" cellpadding="0">
        <tbody>
            <tr>
                <td ><h5 class="txt-green-b"> {$value['title']}<input  value="{$value['a_id']}" type="checkbox" title="全选/不选" name="CheckAll" class="CheckAll{$value['a_id']}" onclick="check{$value['a_id']}()" />h5><hr>  td>
                   <hr>  
            tr>
            <script type="text/javascript">
            function check{$value['a_id']}()
            {
                var a_id =  $(".CheckAll{$value['a_id']}").val();
                console.log(a_id);
                $.ajax({    
                    type:"post",    
                    url:"****",    
                    data:{a_id:a_id},    
                    success:function(data){    
                        var oInput = document.getElementsByClassName('check-box');

                        var obj = JSON.parse(data);
                        $.each(obj, function (key, value) {
                            $.each(oInput, function (keys, values) {
                                if (oInput[keys].value == obj[key]['a_id']) {
                                    var i = $(".CheckAll{$value['a_id']}").attr("checked");
                                    if (i) {
                                        $(oInput[keys]).attr("checked","checked");
                                    }else if (!i) {
                                        $(oInput[keys]).removeAttr("checked");
                                    }
                                }
                            });
                        }); 
                    }    
                });    
            }

        script>

            <tr>
                <td>
                    {foreach $son as $values}   
                    {if condition="($value['a_id'] == $values['parent_id'])"}   
                    <table class="data-data" width="60%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <td class="txt40 c">{$values['title']} :   
                                    {foreach $access as $val}   
                                    {if condition="($values['a_id'] == $val['parent_id'])"} 
                                    <input value="{$val['a_id']}" val="{$val['a_id']}" type="checkbox"  name="CheckBox[{$val['a_id']}]" class="check-box"  /> 
                                    <span class="txt40 c">{$val['title']}  span>
                                    {/if}
                                    {/foreach}
                                td>
                            tr>  
                        tbody>
                    table>
                    {/if}
                    {/foreach}
                td>
            tr> 
        tbody>
    table>
   {/foreach}
div>
将已经添加的权限的复选框显示选中
<script type="text/javascript">
    window.onload=function(){
        var r_id = $("#hidden").val();
        $.ajax({    
            type:"post",    
            url:"****",    
            data:{r_id:r_id},    
            success:function(data){   
                var oInput = document.getElementsByClassName('check-box');
                var obj = JSON.parse(data);
                $.each(obj, function (key, value) {
                    $.each(oInput, function (keys, values) {
                        if (oInput[keys].value == obj[key]) {
                            $(oInput[keys]).attr("checked","checked");
                        }
                    });
                });  
            }    
        });
    }
script>

给角色添加权限和修改权限_第1张图片

你可能感兴趣的:(HTML,jQuery)