标签:
QuanXian.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="../../Public/jquery/jquery-2.2.3.min.js"></script> <title>无标题文档</title> </head> <body> <h1>权限管理</h1> <?php include("../../Public/Connect.class.php"); $con = new Connect(); $sqlu = "select * from users"; $arru = $con->Query_array($sqlu); $sqlj = "select * from juese"; $arrj = $con->Query_array($sqlj); ?> <div>请选择用户:<select id="user"> <?php for($i=0;$i<count($arru);$i++) { echo "<option value = ‘{$arru[$i][0]}‘>{$arru[$i][2]}</option>"; } ?> </select> </div><br /> <div>请选择角色:</div> <div> <?php for($i=0;$i<count($arrj);$i++) { echo "<input type=‘checkbox‘ value=‘{$arrj[$i][0]}‘ class=‘juese‘/>{$arrj[$i][1]} "; } ?> </div><br /> <div><input type="button" value="确定" id="sure"/></div> <script type="text/javascript"> $(document).ready(function(e) { var ckall = $(".juese"); //用变量接收所有复选框以备用 ShowJueSe(); //调用函数,显示默认的第一个人的角色 $("#user").change(function(e) { ShowJueSe(); }); $("#sure").click(function(e) { var uid = $("#user").val(); var juese = ""; //定义一个空字符串备用 for(var i=0;i<ckall.length;i++) //遍历复选框,取得角色代号 { if(ckall.eq(i)[0].checked) { juese += ckall.eq(i).val()+"|"; } } juese = juese.substr(0,juese.length-1); $.ajax({ url:"XiuGai.php", data:{uid:uid,juese:juese}, dataType:"TEXT", type:"POST", success: function(data) { alert(data); } }); }); function ShowJueSe() //封装成函数,以备调用 { var uid = $("#user").val(); $.ajax({ url:"Jschuli.php", data:{uid:uid}, dataType:"TEXT", type:"POST", success: function(data) { $(":checkbox").removeAttr("checked"); //清空所有复选框 if(data.trim() != "") { var hang = data.split("|"); for(var i=0;i<hang.length;i++) { var lie = hang[i].split("^"); //var ckall = $(".juese"); for(var j=0;j<ckall.length;j++) //遍历复选框,显示原有职位为选中状态 { if(ckall.eq(j).val()== lie[2]) { ckall.eq(j).prop("checked",true); } } } } } }); } }); </script> </body> </html>
XiuGai.php
<?php $uid = $_POST["uid"]; $juese = $_POST["juese"]; include("../../Public/Connect.class.php"); $con = new Connect(); $sql = "delete from userinjuese where UserId = ‘{$uid}‘"; //先清空角色,再添加 $con->Query_string($sql,0); $juese = explode("|",$juese); $isOK = true; for($i=0;$i<count($juese);$i++) { $sql = "insert into userinjuese values(‘‘,‘{$uid}‘,‘{$juese[$i]}‘)"; $isOK = $isOK && $con->Query_array($sql,0); } if($isOK) { echo "修改成功!"; } else { echo "修改失败!"; } ?>
JsChuli.php
<?php $uid = $_POST["uid"]; include("../../Public/Connect.class.php"); $con = new Connect(); $sql = "select * from userinjuese where UserId = ‘{$uid}‘"; $str = $con->Query_string($sql); echo $str; ?>
标签:
原文地址:http://www.cnblogs.com/sihuiming/p/5433394.html