你把它改为:
var kt = "rootTree"; 
kt = new dTree("rootTree"); 这样应该就可以了,你试一下看。

解决方案 »

  1.   

    还是不行
    kt = new dTree(kt);
    kt
    这样也不好使啊
    kt它就当kt使
    就是说kt = new dTree(kt);
    左边的kt必须就是new dTree(kt)里的字符串,
    如果kt = new dTree("kt");是对的
    这样就可以建立一棵树,
    但我想建多棵树啊,怎么动态建啊
      

  2.   

    var kt = "rootTree"; 
    var k  = "rootTree"; 
    k = new dTree(kt); 
      

  3.   

    var kt = "rootTree"; 
    kt = new dTree(""+kt+""); 
    这样
      

  4.   

    想作为变量就得var kt = "rootTree"; 
    kt = new dTree(""+kt+"");
      

  5.   

    up up up up up up up 
      

  6.   

    var kt = "rootTree"; 
    kt = new dTree(""+kt+"");
    这个就是让他做变量的
    kt = new dTree(""+kt+"");这个编译后应该是
    kt = new dTree("rootTree");
      

  7.   

    我用
    var kt = "rootTree"; 
    kt = new dTree(""+kt+"");
    这个试了下是可以的啊
      

  8.   

    kt = new dTree("'"+kt+"'");
      

  9.   

    把你所用的dTree.js和你写的代码提供一份,看下你的为什么错
      

  10.   


    <script type="text/javascript" src="dtree.js"></script>
    <script type="text/javascript">
    var kt = "rootTree"; 
    kt = new dTree(""+kt+"");
    kt.add(0,-1,'My example tree');
    kt.add(1,0,'Node 1','example01.html');
    kt.add(2,0,'Node 2','example01.html');
     document.write(kt);</script>
    我测试的代码,正确,正常显示出来My example tree
    Node 1
    Node 2
      

  11.   

    我试了,我这还是不好使啊
    用的就是dtree.js
    <script type="text/javascript" src="dtree.js"></script>
    <script type="text/javascript">
    var kt = "rootTree" + 1; 
    kt = new dTree(""+kt+"");
    kt.add(0,-1,'My example tree');
    kt.add(1,0,'Node 1','example01.html');
    kt.add(2,0,'Node 2','example01.html');
     document.write(kt);var km = "rootTree" + 2; 
    km = new dTree(""+km+"");
    km.add(0,-1,'My example tree');
    km.add(1,0,'Node 1','example01.html');
    km.add(2,0,'Node 2','example01.html');
     document.write(km);</script>
    想这样实现,但不好使
      

  12.   

    忘说了,树是能建出来的 就是点击节点时报错
    html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    <META NAME="Generator" CONTENT="EditPlus">
    <META NAME="Author" CONTENT="">
    <META NAME="Keywords" CONTENT="">
    <META NAME="Description" CONTENT="">
     <link rel="StyleSheet" href="dtree.css" type="text/css" />    
     <script type="text/javascript" src="dtree.js"></script>   
    </HEAD><BODY><div>
       <table>
        <tr>
     <td>
     <table>
     <div>
        <script type="text/javascript">    
            var d = new dTree('d');  
            d.add(0,-1, '');     
    d.add(1,0, 'mmmmm','example01.html');   
            d.add(2,1,'Node 1.1','example01.html');    
            d.add(3,2,'Node 3.1','example01.html');    
            d.add(4,3,'Node 1.1.1','example01.html');    
            d.add(5,4,'Node 1.1.1.1','example01.html');    
            d.add(6,5,'Node 4','example01.html');  
            
    document.write(d);
        </script>
    </div>
    </table>
     </td>
    </tr>
    <tr>
      <td>
      <table>
       <div>
       <script type="text/javascript">    
    var kt = "kt1"
    kt = new dTree("" + kt + "");
            kt.add(10,-1, '');     
            kt.add(11,10,'aaa','example01.html');      
            kt.add(21,11,'Node 1.a','example01.html');    
            kt.add(31,21,'Node 3.b','example01.html');    
            kt.add(41,31,'Node 1.1.c','example01.html');    
            kt.add(51,41,'Node 1.1.1.d','example01.html');    
            kt.add(61,51,'Node 4','example01.html');  
        document.write(kt);
     
           </script>
       </div>
       </table>
      </td>
    </tr>
     </table>
    </div>
    </BODY>
    </HTML>
      

  13.   

    dtree.css
    /*--------------------------------------------------|
    | dTree 2.05 | www.destroydrop.com/javascript/tree/ |
    |---------------------------------------------------|
    | Copyright (c) 2002-2003 Geir Landrö               |
    |--------------------------------------------------*/.dtree {
    font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
    font-size: 11px;
    color: #666;
    white-space: nowrap;
    }
    .dtree img {
    border: 0px;
    vertical-align: middle;
    }
    .dtree a {
    color: black;
    text-decoration: none;
    }
    .dtree a.node, 
    .dtree a.nodeSel {
    white-space: nowrap;
    padding: 1px 2px 1px 2px;
    }.dtree a.node:visited,
    .dtree a.nodeSel:visited {
    color: blue;
    text-decoration: underline;
    }.dtree a.nodeSel {
    background-color: white;
    }
    .dtree .clip {
    overflow: hidden;
    }
      

  14.   

    忘说了,树是能建出来的 就是点击节点时报错 这个就与这里没有关系了
    是你dtree.js的问题了
      

  15.   

    恩....对 点击节点时
    就是在dTree.js里找不到kt1
    如果要修改dTree.js的话. 会挺麻烦的
    有改过的吗
      

  16.   

    关键几处代码
    :dTree.prototype.s = function(id) { if (!this.config.useSelection) return; var cn = this.aNodes[id]; if (cn._hc && !this.config.folderLinks) return; if (this.selectedNode != id) { if (this.selectedNode || this.selectedNode==0) { eOld = document.getElementById("s" + this.obj + this.selectedNode); eOld.className = "node"; } eNew = document.getElementById("s" + this.obj + id); eNew.className = "nodeSel"; this.selectedNode = id; if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id); }};
      

  17.   

    dTree.prototype.node = function(node, nodeId) { var str = '<div 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 += '<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '" alt="" />'; } if (node.url) { str += '<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"'; 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 += '>'; } else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id) str += '<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">'; str += node.name; if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) str += '</a>'; str += '</div>'; if (node._hc) { str += '<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">'; str += this.addNode(node); str += '</div>'; } this.aIndent.pop();
    alert(str);
    return str;};
      

  18.   

     我试了,我这还是不好使啊 
    谢谢帮忙.....haha
      

  19.   

    使用alert()去检测
    比如我24楼的
      this.aIndent.pop();
    alert(str);
        return str;
    加了这个检测