dTree.prototype.node = function (node, nodeId)
{
    
    var divSelected = "onmouseover = \"this.style.backgroundColor='#FFF250';\" onmouseout = \"this.style.backgroundColor='#FFFFFF';\"";
    var str = "<div  "+divSelected+"  class=\"dTreeNode\">" + this.indent(node, nodeId);
    
    if (this.config.useIcons)
    { 
        if (!node.icon)
        {
            node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
        }
        if (!node.iconOpen)
        {
            node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
        }
        if (this.root.id == node.pid)
        {
            node.icon = this.icon.root;
            node.iconOpen = this.icon.root;
            
        }
        str += "<span style=\"width:300px;overflow:hidden; text-overflow:ellipsis; white-space:nowrap;\"><img id=\"i" + this.obj + nodeId + "\" src=\"" + ((node._io) ? node.iconOpen : node.icon) + "\" alt=\"\" />";
    //添加上复选框
       
        if (this.config.check == true) {
        
             str += '<input value="  " name="xyz" type="checkbox" id="c' + this.obj + node.id
                    + '" onclick="javascript:' + this.obj + '.cc(' + node.id
                    + ',' + node.pid + ')"/>';
        } 
    }
    //alert(xyz);
    //style="background: b4b4b4;border:0px"
    //最后要为点中复选框的事件添加cc方法//点击复选框onclick事件
  
dTree.prototype.cc=function(nodeId, nodePid){
    
    //首先获取这个多选框的id 
    var cs = document.getElementById("c" + this.obj + nodeId).checked;
    //alert(nodeId+"==");
    var n,node = this.aNodes[nodeId];
    var len = this.aNodes.length;
    for (n=0; n<len; n++) { //如果循环每一个节点 
        if (this.aNodes[n].pid == nodeId) { //如果选中的是非叶子节点,则要将所有的子节点选择和父节点一样 
            document.getElementById("c" + this.obj + this.aNodes[n].id).checked = cs;           
            this.cc(this.aNodes[n].id, nodeId);   
        }         
    }  
    
     if(cs==true){  //当前是选中状态
        var pid=nodePid;  
        
         
        var bSearch;  
        do{  
            bSearch=false;  
            for(n=0;n<len;n++){  //循环每一个节点 
                if(this.aNodes[n].id==pid){  //如果循环的节点的id等于PID 
                    document.getElementById("c"+this.obj+pid).checked=true; //那么这个循环的节点应该被选中  
                    pid=this.aNodes[n].pid;  
                    bSearch= true;        
                    break;    
                }    
            }    
        }while(bSearch==true);
      }
      
      if(cs==false){      //如果被取消选择 
        var pid = nodePid;  
        do{    
            for(j=0;j<len;j++){         //循环每一个多选框  如果这个节点的子节点有其他是选中的,则不取消 
                if(this.aNodes[j].pid==pid && document.getElementById("c" + this.obj + this.aNodes[j].id).checked==true){                 
                    return;  
                }  
            }  
            if(j==len){   //循环结束 
                for(k=0;k<len;k++){    
                    if(this.aNodes[k].id==pid){   //如果找到父节点 
                        document.getElementById("c"+this.obj+this.aNodes[k].id).checked=false;    
                        pid=this.aNodes[k].pid;   
                        break;  
                    }       
                }    
            }    
        }while(pid!=-1);      
    }
}
 如何把粉红pid,赋给红色颜色value?

解决方案 »

  1.   

    通过this传递就行了var pid=nodePid;  
    this._pid = pid;然后 '<input value="'+this._pid+'" name="x......
      

  2.   

    输出结果:undefined
    声明:var pid=nodePid;
          alert(pid);是能弹出正确结果的。
      

  3.   

    输出结果:undefined
    声明:var pid=nodePid;
          alert(pid);是能弹出正确结果的。
    剩下的是纯粹的逻辑问题了,node方法执行时cc方法是否已经执行,自己不会调?
      

  4.   

    输出结果:undefined
    声明:var pid=nodePid;
          alert(pid);是能弹出正确结果的。
    剩下的是纯粹的逻辑问题了,node方法执行时cc方法是否已经执行,自己不会调?
    cc方法是 checkbox 里onclick调用的,哥,我真不会掉,您给个正确结果吧,我加分。