js控制treeview 只能选择一种节点 :有子节点 或 无子节点 的节点

function SetTreeNodeOneTypeClickHander(treeID) {  
    var objs = document.getElementsByTagName("input");
    for (var i = 0; i < objs.length; i++) {
        if (objs[i].type == 'checkbox') {
            var obj = objs[i];
            if (obj.id.indexOf(treeID) != -1) {
                objs[i].onclick = function() { TreeSingleTypeSelect(treeID, this); };
            }
        }
    }
}

function TreeSingleTypeSelect(treeID, checkNode)
{
     if (!treeID)        return;
     var objs = document.getElementsByTagName("input");
     var DivID =checkNode.id.replace('CheckBox','Nodes');
     var div = document.getElementById(DivID);
     var i;
    
     if(div!=null)//说明选中的为父节点
     {
        for( i=0;i        {
            if(objs[i].type=='checkbox')
            {
              var childrenDivID=objs[i].id.replace('CheckBox','Nodes');
              var childrendiv = document.getElementById(childrenDivID); 
              if(childrendiv==null&&checkNode.checked) objs[i].checked=!checkNode.checked;
            }
          
        }
     }
     else
     {
        for( i=0;i        {
            if(objs[i].type=='checkbox')
            {
              var childrenDivID=objs[i].id.replace('CheckBox','Nodes');
              var childrendiv = document.getElementById(childrenDivID); 
              if(childrendiv!=null&&checkNode.checked) objs[i].checked=!checkNode.checked;
            }
          
        }
     }
   
}

你可能感兴趣的:(js控制treeview 只能选择一种节点 :有子节点 或 无子节点 的节点)