别看代码很多……%其实我问的问题很简单啊 ,我想让第一个checkbox能够全选后面他的组员,该怎么实现啊 求大伙帮帮忙了。
--------------------------------------------------------------------------------------------------------------<?php
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");$link=db_connect();
$empire=new mysqlquery();
//验证用户
$lur=is_login();
$logininid=$lur['userid'];
$loginin=$lur['username'];
$loginrnd=$lur['rnd'];
$loginlevel=$lur['userlevel'];$loginadminstyleid=$lur['adminstyleid'];
$sitegroupid = $lur['sitegroupid'];//默认值
$defaultvalue="";
$enews=$_GET['enews'];
$roleid=(int)$_GET['roleid'];
$rolename=(string)$_GET['rolename'];
$url="位置:<a href=ListRole.php>管理角色</a> > 角色授权:<b>".$rolename."</b>";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>角色授权</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<script>
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e != null)
{
//alert(e.tagName);
//alert(e.type);
var checked = new Boolean(form.chkall.checked) ;
var checkvalue = "false" ;
if (checked == true)
{
checkvalue = "true";
}
if (e.tagName.toLowerCase()=='input'
&& e.type.toLowerCase()=="checkbox" && e.name != 'chkall')
{
e.checked = form.chkall.checked ;
e.value = checkvalue ;
}
}
}
}
</script></head>
<body>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><?=$url?></td>
</tr>
</table>
<form name="form1" method="post" action="ListRole.php">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr bgcolor="#FFFFFF">
<td height="25" width="10%"> </td>
<td height="25" width="90%" align="right">
<input name="enews" type="hidden" id="enews" value="<?=$enews?>">
<input name="roleid" type="hidden" id="roleid" value="<?=$roleid?>">
<input name="rolename" type="hidden" id="rolename" value="<?=$rolename?>">
<input type=checkbox name=chkall value=on onclick=CheckAll(this.form) align="left">全部选中
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
<?php
//站群管理协作平台的一级菜单 and isvalid = 1
//-----------------------------------------1、加载一级菜单功能组--------------------------
$record_group_1 =$empire->query("select groupid,groupname from bap_function_group
where systemid=1000 and parentid=0 and isvalid=1
order by pindex");
while($record_1=$empire->fetch($record_group_1))
{
$groupid_1=$record_1[groupid];
$groupname_1=$record_1[groupname];
//该功能组及其下级组所属的功能
$record_function=$empire->query("select a.functionid,a.functionname,b.RightValue
from bap_function as a
left join bap_role_function as b on a.functionid=b.functionid and b.roleid=$roleid
where (a.groupid=$groupid_1
or a.groupid in (select groupid from bap_function_group where parentid=$groupid_1))
and a.isvalid = 1
order by a.groupid,a.pindex");
$functionrows=mysql_num_rows($record_function);
if ($functionrows>0)
{
?>
<tr bgcolor="#FFFFFF">
<td height="25" width="10%"><?=$groupname_1?>
<input type=checkbox name=chkall value=on onclick=CheckAll(this.form) align="left">
<td height="25" width="90%">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<?php
//-----------------------------2、加载一级、二级菜单功能组下的功能
$loopindex=0;
while($fun=$empire->fetch($record_function))
{
$functionid = $fun[functionid];
$functionname = $fun[functionname];
$codevalue = $fun[codevalue];
$RightValue = $fun[RightValue] ;
$checked = "" ;
$checkvalue="false" ;
if(!is_null($fun[RightValue]))
{
if($fun[RightValue])
{
$checked = " checked" ;
$checkvalue="true" ;
}
}
$ctrname=(string)$functionid ;
$intmod=$loopindex % 4 ;
if($intmod==0)
{
?>
<tr>
<?
}
?>
<td width="25%" height="23">
<input name="field[<?=$ctrname?>]" type="checkbox"
id="field[<?=$ctrname?>]"
value="<?=$checkvalue?>"<?=$checked?>><?=$functionname?>
</td>
<?php
$loopindex+=1 ;
$intmod=$loopindex % 4 ;
if($intmod==0 || $loopindex==$functionrows)
{
//当前功能组中的所有功能循环结束后,根据余数情况,要补空行
$addrows = 4-$intmod ;
$num = 0 ;
if($loopindex==$functionrows && $addrows > 0 && $intmod >0)
{
do{
?>
<td height="23"> </td>
<?php
$num +=1;
}while ($num < $addrows);
}
?>
</tr>
<?php
}
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</form>
</body>
</html>
<?php
db_close();
$empire=null;
?>
--------------------------------------------------------------------------------------------------------------<?php
require("../../class/connect.php");
require("../../class/db_sql.php");
require("../../class/functions.php");$link=db_connect();
$empire=new mysqlquery();
//验证用户
$lur=is_login();
$logininid=$lur['userid'];
$loginin=$lur['username'];
$loginrnd=$lur['rnd'];
$loginlevel=$lur['userlevel'];$loginadminstyleid=$lur['adminstyleid'];
$sitegroupid = $lur['sitegroupid'];//默认值
$defaultvalue="";
$enews=$_GET['enews'];
$roleid=(int)$_GET['roleid'];
$rolename=(string)$_GET['rolename'];
$url="位置:<a href=ListRole.php>管理角色</a> > 角色授权:<b>".$rolename."</b>";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>角色授权</title>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css">
<script>
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e != null)
{
//alert(e.tagName);
//alert(e.type);
var checked = new Boolean(form.chkall.checked) ;
var checkvalue = "false" ;
if (checked == true)
{
checkvalue = "true";
}
if (e.tagName.toLowerCase()=='input'
&& e.type.toLowerCase()=="checkbox" && e.name != 'chkall')
{
e.checked = form.chkall.checked ;
e.value = checkvalue ;
}
}
}
}
</script></head>
<body>
<table width="98%" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><?=$url?></td>
</tr>
</table>
<form name="form1" method="post" action="ListRole.php">
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
<tr bgcolor="#FFFFFF">
<td height="25" width="10%"> </td>
<td height="25" width="90%" align="right">
<input name="enews" type="hidden" id="enews" value="<?=$enews?>">
<input name="roleid" type="hidden" id="roleid" value="<?=$roleid?>">
<input name="rolename" type="hidden" id="rolename" value="<?=$rolename?>">
<input type=checkbox name=chkall value=on onclick=CheckAll(this.form) align="left">全部选中
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</td>
</tr>
<?php
//站群管理协作平台的一级菜单 and isvalid = 1
//-----------------------------------------1、加载一级菜单功能组--------------------------
$record_group_1 =$empire->query("select groupid,groupname from bap_function_group
where systemid=1000 and parentid=0 and isvalid=1
order by pindex");
while($record_1=$empire->fetch($record_group_1))
{
$groupid_1=$record_1[groupid];
$groupname_1=$record_1[groupname];
//该功能组及其下级组所属的功能
$record_function=$empire->query("select a.functionid,a.functionname,b.RightValue
from bap_function as a
left join bap_role_function as b on a.functionid=b.functionid and b.roleid=$roleid
where (a.groupid=$groupid_1
or a.groupid in (select groupid from bap_function_group where parentid=$groupid_1))
and a.isvalid = 1
order by a.groupid,a.pindex");
$functionrows=mysql_num_rows($record_function);
if ($functionrows>0)
{
?>
<tr bgcolor="#FFFFFF">
<td height="25" width="10%"><?=$groupname_1?>
<input type=checkbox name=chkall value=on onclick=CheckAll(this.form) align="left">
<td height="25" width="90%">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<?php
//-----------------------------2、加载一级、二级菜单功能组下的功能
$loopindex=0;
while($fun=$empire->fetch($record_function))
{
$functionid = $fun[functionid];
$functionname = $fun[functionname];
$codevalue = $fun[codevalue];
$RightValue = $fun[RightValue] ;
$checked = "" ;
$checkvalue="false" ;
if(!is_null($fun[RightValue]))
{
if($fun[RightValue])
{
$checked = " checked" ;
$checkvalue="true" ;
}
}
$ctrname=(string)$functionid ;
$intmod=$loopindex % 4 ;
if($intmod==0)
{
?>
<tr>
<?
}
?>
<td width="25%" height="23">
<input name="field[<?=$ctrname?>]" type="checkbox"
id="field[<?=$ctrname?>]"
value="<?=$checkvalue?>"<?=$checked?>><?=$functionname?>
</td>
<?php
$loopindex+=1 ;
$intmod=$loopindex % 4 ;
if($intmod==0 || $loopindex==$functionrows)
{
//当前功能组中的所有功能循环结束后,根据余数情况,要补空行
$addrows = 4-$intmod ;
$num = 0 ;
if($loopindex==$functionrows && $addrows > 0 && $intmod >0)
{
do{
?>
<td height="23"> </td>
<?php
$num +=1;
}while ($num < $addrows);
}
?>
</tr>
<?php
}
}
?>
</table>
</td>
</tr>
<?php
}
}
?>
</table>
</form>
</body>
</html>
<?php
db_close();
$empire=null;
?>
<script>
function CheckOthers(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e.checked==false)
{
e.checked = true;
}
else
{
e.checked = false;
}
}
}
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
e.checked = true;
}
}
</script><form name="form1" method="post" action="">
<input type="checkbox" value="" name="chkall" onClick="CheckAll(this.form)"/>全選
<input type="checkbox" value="" name="chkothers" onClick="CheckOthers(this.form)"/>複選
<br /><br />
<input type="checkbox" >
<br>
<input type="checkbox" >
<br>
<input type="checkbox" >
<br>
<input type="checkbox" >
<br>
<input type="checkbox" >
<br></form>
可是我没报错啊
就是我想加一个checkbox可以实现对每组的全选,不是所有选项的全选只是对每组的 你运行一下看一下就知道了啊
你运行一下代码 看看就知道了啊
<script language="javascript">
function checkAll(obj){
var childinput = obj.parentNode.parentNode.getElementsByTagName("input");
for(i=0;i<childinput.length;i++){
childinput[i].checked=obj.checked;
}
}
</script>
然后调用这里换成onclick=CheckAll(this)