要求:子节点全选中,父节点全选中,否则不洗;当然父节点选中下面的子节点全选中。
     取值要求:如果下面的子节点全选中,那么我们只选父节点值。否则只选子节点的值。

解决方案 »

  1.   

    即使使用框架 都没有这种现成的需求 
    几个常用的tree:
    Ext的TreePanel 
    easy ui 的tree
    TreeView
    这些框架 也都需要我们自己去修改 楼主如果js还可以的话 可以去试试
      

  2.   

    以前我多数用dtree,但是后来我发现了个好的,给您推荐一下:ztree
      

  3.   

    treeview demo
    各种花样 。
      

  4.   

    刚写了一个实例,你可以参考下 
    <input type="checkbox" name="parent" onclick="judge()"/>我是好父亲<br/><br/><input type="checkbox" name="son" onclick="judgeSelectAll()"/>我是大儿子<br/>
    <input type="checkbox" name="son" onclick="judgeSelectAll()"/>我是二儿子<br/>
    <input type="checkbox" name="son" onclick="judgeSelectAll()"/>我是小儿子<br/>
    <input type="button" value="测试一下" onclick="out()"/><script>
       
      var isParentChecked = false;
      function judge(){
        var sons = document.getElementsByName('son');
    if(!isParentChecked){
    SelectAll(true);
    isParentChecked = true;
    }else{
    SelectAll(false);
    isParentChecked = false;
    }
      }
      function judgeSelectAll(){
        var sons = document.getElementsByName('son');
    var parent = document.getElementsByName('parent')[0];
        isParentChecked = true;
        parent.checked = true;
    for(var i=0;i<sons.length;i++){
      if(!sons[i].checked){
       isParentChecked = false;
           parent.checked = false;
      }
    }
      }
      function SelectAll(flag){
        var sons = document.getElementsByName('son');
    for(var i=0;i<sons.length;i++){
      sons[i].checked = flag;
    }
      }
      //这里你就可以编写自己需要的代码了
      function out(){
       if(isParentChecked){
        alert('传出父节点的值');
       }else{
        alert('传出子节点的值');
       }
      }
      
    </script>
    不明白的加我QQ把你弄明白为止
      

  5.   

    这个 可能满足你http://www.baby666.cn/hunter/zTree.html
    zTree 
      

  6.   

    // Node objectfunction Node(id, pid, name, url, leaf,title, target, icon, iconOpen, open) { this.id = id; this.pid = pid; this.name = name; this.url = url;

    this.leaf = leaf; this.title = title; this.target = target; this.icon = icon; this.iconOpen = iconOpen; this._io = open || false; this._is = false; this._ls = false; this._hc = false; this._ai = 0; this._p;};// Tree objectfunction dTree(objName,rootid,img) { this.config = { target : null,
    linksAttr :null, folderLinks : true, useSelection : true, useCookies : false, useLines : true, useIcons : true, useStatusText : true, closeSameLevel : true,

    closeSameLevel : true,

    checkbox :false,

    radiobox :true,

    allnode :true,
    newLine :10,
    inOrder : false } this.icon = {
    point :img+'/images/treeImg/point.gif', root : img+'/images/treeImg/base.gif', folder : img+'/images/treeImg/folder.gif', folderOpen : img+'/images/treeImg/folderopen.gif', node : img+'/images/treeImg/page.gif', empty : img+'/images/treeImg/empty.gif', line : img+'/images/treeImg/line.gif', join : img+'/images/treeImg/join.gif', joinBottom : img+'/images/treeImg/joinbottom.gif', plus : img+'/images/treeImg/plus.gif', plusBottom : img+'/images/treeImg/plusbottom.gif', minus : img+'/images/treeImg/minus.gif', minusBottom : img+'/images/treeImg/minusbottom.gif',

    enter    : img+'/images/treeImg/enter.gif',

    enterDown    : img+'/images/treeImg/enterDown.gif', nlPlus : img+'/images/treeImg/enter.gif', nlMinus : img+'/images/treeImg/enterDown.gif' }; this.obj = objName; this.aNodes = []; this.aIndent = []; this.root = new Node(-1); this.selectedNode = null; this.selectedFound = false; this.completed = false;
    this.rootid=rootid;};
      

  7.   

    // Adds a new node to the node arraydTree.prototype.add = function(id, pid, name, url, leaf,title, target, icon, iconOpen, open) { this.aNodes[this.aNodes.length] = new Node(id, pid, name, url, leaf,title, target, icon, iconOpen, open);};// Open/close all nodesdTree.prototype.openAll = function() { this.oAll(true);};dTree.prototype.closeAll = function() { this.oAll(false);};// Outputs the tree to the pagedTree.prototype.toString = function() { var str = '<table cellpadding=0  cellspacing=0 border=0 class="dtree">\n'; if (document.getElementById) { if (this.config.useCookies) this.selectedNode = this.getSelected(); str += this.addNode(this.root); } else str += 'Browser not supported.'; str += '</table>'; if (!this.selectedFound) this.selectedNode = null; this.completed = true;
    //textarea.value=str;
    return str;};// Creates the tree structuredTree.prototype.addNode = function(pNode) { var str = ''; var n=0; if (this.config.inOrder) n = pNode._ai; for (n; n<this.aNodes.length; n++) { if (this.aNodes[n].pid == pNode.id) { var cn = this.aNodes[n]; cn._p = pNode; cn._ai = n;
    this.setCS(cn); if (!cn.target && this.config.target) cn.target = this.config.target; if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id); if (!this.config.folderLinks && cn._hc) cn.url = null; if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) { cn._is = true; this.selectedNode = n; this.selectedFound = true; } str += this.node(cn, n); if (cn._ls) break; } } return str;};
      

  8.   

    // Creates the node icon, url and text dTree.prototype.node = function(node, nodeId) {
    var str='<tr><td>';
        str += '<table cellpadding=0  cellspacing=0 border=0 class="dTreeNode"> <tr><td valign="top">' + this.indent(node, nodeId);
        str +='</td><td><table cellpadding=0 cellspacing=0 border=0 ><tr><td>';
    if(this.config.checkbox)
    str+=' <input type="checkbox" name="chkbox"  value="'+node.id+'" id="c'+ this.obj + nodeId + '" onclick="javascript:'+this.obj+'.selectNodes('+nodeId+')"> ';
    if(this.config.radiobox&&!node._hc)
    str+=' <input type="radio" name="radiobox"  value="'+node.id+'" id="c'+ this.obj + nodeId + '" onclick="javascript:'+this.obj+'.selectNodes('+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 += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />'; }

    if (node.url) {
    //alert(node.url);
    //str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + this.config.linksAttr+'&root_id='+this.rootid+'&node_id='+node.id+'"';
    str += '<span onfocus="blur()" id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '"';


    if (node.title) str += ' title="' + node.title + '"'; if (node.target) str += ' target="' + node.target + '"'; if (this.config.useStatusText) str += ' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" '; if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc)) str += ' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"'; str += '>'; }