js实现checkbox多级选择
<script type="text/javascript">
function chose(obj){
var funid= obj.id;
var f = window.document.sysRoleForm;
var ele = f.elements;
var len = funid.length;
var lent = len/3;
var endsub = len-3;
var count = 0;
var tolcount =0;
switch(obj.checked){
case true:{
for (var i = 0; i < ele.length; i++) {
var name = ele[i].id;
if(name.indexOf(funid)==0){
document.sysRoleForm.all(name).checked=true;
}
}
for(i=1;i<lent;i++){
var sub = funid.substring(0,endsub);
endsub=endsub-3;
document.sysRoleForm.all(sub).checked=true;
}
break;
}
case false:{
for (var i = 0; i < ele.length; i++) {
var name = ele[i].id;
var nlen = name.length;
if(name.indexOf(funid)==0){
document.sysRoleForm.all(name).checked=false;
}
if(nlen>3){
var subname = name.substring(0,nlen-3);
if(nlen==len && funid.indexOf(subname)==0){
count = count +1 ;
}
if(nlen==len && funid.indexOf(subname)==0 && document.sysRoleForm.all(name).checked==false){
tolcount = tolcount +1 ;
}
}
}
if(count==tolcount && count!=0 && tolcount !=0){
subfunid = funid.substring(0,endsub)
document.sysRoleForm.all(subfunid).checked=false;
}
break;
}
}
}
</script>