checkbox多级联动
<HTML>
<HEAD>
<TITLE> </TITLE>
<script language="javascript">
function selectcheckbox()
{
var Obj;
Obj = window.event.srcElement;
nid=Obj.id.substring(1);
var nnck=document.all(nid);
nnck.checked=!nnck.checked;
nnck.onpropertychange=function(){
down(nnck);
up(nnck);
}
}
var myID = "ID";
var myName = "Name";
function filter() {
var Obj = window.event.srcElement;
nid=Obj.id.substring(1);
fid=Obj.id.substring(0,1);
if (fid=='n')
{
var Obj=document.all(nid);
Obj.checked=!Obj.checked;
if (Obj.indeterminate) Obj.indeterminate=false;
}
if ((Obj.type == "checkbox" && (Obj.className == "dept" || Obj.className == "employee"))||fid=='n'){
down(Obj);
up(Obj);
}else{
}
}
function down(theObj) {
var subObjects;
var subObjectID;
if(theObj != null) {alert('1');
subObjectID = theObj.id.substring(0,2) + theObj.name.substring(4);
subObjects = document.all(subObjectID);
if(subObjects != null) {
if(subObjects.length) {
for(var i=0;i<subObjects.length;i++) {
subObjects[i].checked = theObj.checked;
if (subObjects[i].indeterminate) subObjects[i].indeterminate=false;
down(subObjects[i]);
}
}else{
subObjects.checked = theObj.checked;
}
}
}else{
return;
}
}
function up(theObj) {
var bortherObj;
var parentObj;
var parentObjName;
var flag = 0;
if((theObj != null) && (theObj.value != "")) {
parentObjName = theObj.name.substring(0,4) + theObj.id.substring(2);
parentObj = document.all(parentObjName);
if(parentObj != null) {
bortherObj = document.all(theObj.id);
if(bortherObj.length) {
for(var i=0;i<bortherObj.length;i++) {
if((bortherObj[i].checked != theObj.checked) || bortherObj[i].indeterminate || theObj.indeterminate) {
flag = 1;
break;
}
}
if(flag == 0) {
parentObj.checked = theObj.checked;
parentObj.indeterminate = false;
}else{
parentObj.checked = true;
parentObj.indeterminate = true;
}
}else{
parentObj.checked = theObj.checked;
parentObj.indeterminate = theObj.indeterminate;
}
up(parentObj);
}else{
return;
}
}else{
return;
}
}
function getChkValue(theObj,result) {
var ID = "";
var subObjects;
var subObjectID;
if(theObj != null) {
if(theObj.indeterminate) {
}else{
if(theObj.className == "employee") {
result += (theObj.checked?("," + theObj.name.substring(myName.length)):"");
}
}
subObjectID = myID + theObj.name.substring(myName.length);
subObjects = document.all(subObjectID);
if(subObjects != null) {
if(subObjects.length) {
for(var i=0;i<subObjects.length;i++) {
result = getChkValue(subObjects[i],result);
}
}else{
if(subObjects.className == "employee") {
result += (subObjects.checked?("," + subObjects.name.substring(myName.length)):"");
}
}
}
}else{
return result;
}
return result;
}
function mySubmit() {
var result = "";
//result = getChkValue(document.all("Named01"),result);
if(result != "") {
result = result.substring(1);
}
show(result);
return false;
}
function show(msg) {
document.all("show").value = msg;
}
document.onclick = filter;
</script>
</HEAD>
<BODY>
<table width="100%" cellspacing="0" cellpadding="0">
<tr height="60pt">
<td></td>
</tr>
<tr height="60pt">
<td><pre>
</pre></td>
</tr>
<tr>
<td><input type="checkbox" class="dept" id="ID" name="Named01"><a onClick="" style="cursor:hand" id="nID">部门d01</a></input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="IDd01" name="Named02">部门d02</input></td>
</tr>
<tr><td>
<input type="checkbox" class="employee" id="IDd02" name="Namee01">员工e01</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="IDd02" name="Named05">部门d05</input></td>
</tr>
<tr><td>
<input type="checkbox" class="employee" id="IDd05" name="Namee02">员工e02</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="IDd01" name="Named03">部门d03</input></td>
</tr>
<tr><td>
<input type="checkbox" class="employee" id="IDd03" name="Namee03">员工e03</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="IDd01" name="Named04">部门d04</input></td>
</tr>
<br>
<br>
<tr>
<td><input type="checkbox" class="dept" id="IC" name="Namec01">部门c01</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="ICc01" name="Namec02">部门c02</input></td>
</tr>
<tr><td>
<input type="checkbox" class="employee" id="ICc02" name="Namee01">员工e01</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="ICc02" name="Namec05">部门c05</input></td>
</tr>
<tr><td>
<input type="checkbox" class="employee" id="ICc05" name="Namee02">员工e02</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="ICc01" name="Namec03">部门c03</input></td>
</tr>
<tr><td>
<input type="checkbox" class="employee" id="ICc03" name="Namee03">员工e03</input></td>
</tr>
<tr><td>
<input type="checkbox" class="dept" id="ICc01" name="Namec04">部门c04</input></td>
</tr>
</table>
</BODY>
</script>
</HTML>

浙公网安备 33010602011771号