一个带CheckBox的树形目录javascript的递归算法
var head="display:''"
img_close=new Image()
img_close.class="lazy" data-src="/sysManage/images/f.gif"
img_open=new Image()
img_open.class="lazy" data-src="/sysManage/images/fo.gif"
img3=new Image()
img3.class="lazy" data-src="/sysManage/images/e.gif";
var elment = img_close.class="lazy" data-src
function onMouseDown(){
if(!document.all)return
var eventObj = event.class="lazy" data-srcElement;
if(eventObj.tagName=="IMG" ) {
//判断是否存在子节点
var sclass="lazy" data-src = eventObj.class="lazy" data-src ;
if(sclass="lazy" data-src == null || sclass="lazy" data-src.length<=0)return;
if(sclass="lazy" data-src.indexOf("e.gif") >= 0)return;
if(sclass="lazy" data-src.indexOf("f")<0 && sclass="lazy" data-src.indexOf("tree-site")<0 )return;
var nOffIndex = 2;
var class="lazy" data-srcIndex = eventObj.sourceIndex;
var nested = document.all[class="lazy" data-srcIndex + nOffIndex];
if(nested.tagName!="DL"){
nested = document.all[class="lazy" data-srcIndex + 1];
}
if (nested.style.display=="none") {
nested.style.display='inline';
if(sclass="lazy" data-src.indexOf("f.gif")>0)
eventObj.class="lazy" data-src = img_open.class="lazy" data-src;
}
else {
nested.style.display="none";
if(sclass="lazy" data-src.indexOf("fo.gif")>0)
eventObj.class="lazy" data-src = img_close.class="lazy" data-src;
}
}else if(eventObj.tagName == "A" ){//相应节点的点击
var nChnlId = parseInt(eventObj.name);
if(!isNaN(nChnlId)){
onClickChannel(nChnlId);
}
}
}
function checkNode(obj)
{
var elm = obj.parentNode;
checkChildrenRecurve(elm);
//checkRootRecurve(document.getElementById("root"));
}
function checkChildrenRecurve(elm)
{
var dd = elm;
var dl = dd.lastChild;
if (dl.tagName != "DL") return;
var ddlist = dl.children;
for (var i=0;i
ddlist[i].firstChild.checked=elm.firstChild.checked;
checkChildrenRecurve(ddlist[i].firstChild.parentNode)
}
}
function checkRootRecurve(dl)
{
if (dl.tagName != "DD")
{
dl.parentNode.firstChild.firstChild.allChecked = dl.parentNode.firstChild.firstChild.checked;
dl.parentNode.firstChild.firstChild.allUnChecked = !dl.parentNode.firstChild.firstChild.checked;
return;
}
var lis = dl.children;
var allChecked = true;
var allUnChecked = true;
for (var i=0;i
checkRootRecurve(lis[i].lastChild);
allChecked = allChecked && lis[i].firstChild.firstChild.checked && lis[i].firstChild.firstChild.allChecked;
allUnChecked = allUnChecked && !lis[i].firstChild.firstChild.checked && lis[i].firstChild.firstChild.allUnChecked;
}
dl.parentNode.firstChild.firstChild.allChecked=allChecked;
dl.parentNode.firstChild.firstChild.allUnChecked=allUnChecked;
if (allChecked || allUnChecked)
{
dl.parentNode.firstChild.firstChild.checked=allChecked;
dl.parentNode.firstChild.firstChild.disabled=false;
dl.parentNode.firstChild.childStatus=false;
}
else
{
dl.parentNode.firstChild.firstChild.disabled=true;
dl.parentNode.firstChild.childStatus=true;
dl.parentNode.firstChild.firstChild.checked=true;
}
}
document.onclick=onMouseDown
function selParentNode(nodeIDStr,spltStr){
var nodeLen=nodeIDStr.length;
var nodeList;
if(nodeLen<1){
return;
}
nodeIDList = nodeIDStr.split(spltStr);
for (j=0;j
if(checkSubNode(nodeIDList[j]))
{
for (var k=0;k
if(form1.chkID[k].value == nodeIDList[j] )
{
form1.chkID[k].checked = true;
break;
}
}
}
}
}
function checkSubNode(curNodeID) {
for (var i=0;i
if (form1.chkID[i].value.substring(0,curNodeID.length) == curNodeID && form1.chkID[i].value.length >= (curNodeID.length +2) )
{
if(!form1.chkID[i].checked )
{
return false;
}
}
}
return true;
}
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341