javascript:%20oc('qz.cube_qz01',%201,'cubeopen.ico'%20,%20'cubeclose.ico');
这句话看不懂,如果说可能报错,最好贴出你tree的代码了

解决方案 »

  1.   

    楼主,我特意拿你的代码测试了一遍,正常,我自己编写了一个test.htm,并用你的页面调用,可以正常打开;所以我认为可能与你的tree代码有关系,你给的这段代码是没问题的!
      

  2.   

    javascript:%20oc('qz.cube_qz01',%201,'cubeopen.ico'%20,%20'cubeclose.ico');
    这种错误很少见,看一下是不是你的tree.htm的路径有问题。
      

  3.   

    谢谢各位大哥的参与,这是tree.htm的代码,我要处理的是一个xml文档<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
    <link rel="StyleSheet" href="tree.css" type="text/css">
    <script type="text/javascript" src="tree.js"></script>
     
    <script type="text/javascript">
     
    //--------------------- var metadatadoc   = new ActiveXObject("Microsoft.XMLDOM") ;  
     var metatree = new Array ;    
     var valuestr ="" ; 
     var nodeId ,parentNodeId ,nodeName ,nodeUrl ,closeImge ,openImge ;
     
     var cubeopen      ="'cubeopen.ico'" ;
     var cubeclose     ="'cubeclose.ico'" ;
        
     var dementionfolderopen ="'dementionfolderopen.ico'"    ;
     var dementionfolderclose ="'dementionfolderclose.ico'"  ;
     var demention     ="'demention.ico'" ; 
     
     var ready =false ; 
     
     nodeId =parentNodeId= nodeName =nodeUrl=closeImage=openImage= 0 ;  
     
     var userNodeId = window.dialogArguments;             //获得用户选择的id     var oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
     var server ="http://192.1.1.115/webolap/metadata.aspx" ;
     
     oXmlHttp.Open("POST",server, false);
     oXmlHttp.setRequestHeader("Content-Type","text/xml") ;
     oXmlHttp.Send("<?xml version='1.0' ?> ");   metadatadoc.loadXML(oXmlHttp.responseXML.xml); // 
     // 根据用户点击的节点id,得到该节点的位置,并且向上查找各个父亲节点
     // 如果找着最上层的父亲节点,从该节点开始向下查找,并成生树的节点
     //  function findtop(id) 
     {
       //var usernode  =  metadatadoc.selectSingleNode("//cubeid[@id='" + id + "']") ; 
        var usernode  =  metadatadoc.selectSingleNode("//dementionid[@id='" + "qz.cube_qz01.d_year" + "']") ;  
        for( ;;)
         {
          if( usernode.parentNode.tagName !="cubeid") 
                  usernode = usernode.parentNode ; 
          else 
               break ;  
         } 
         return usernode ; 
      }
       
     function maketreenode(parentnode) 
     {  
        var imageopen  ,imageclose ;
        var link ="#" ;  
        for(var  i=0 ; i < parentnode.childNodes.length ; i++ )            
        { 
            nodeId   = parentnode.childNodes[i].getAttribute("id") ;  
            nodeName = parentnode.childNodes[i].getAttribute("desc") ;  
            
            var nodeType  =parentnode.childNodes[i].getAttribute("datatype") ;
            var formatstr =parentnode.childNodes[i].getAttribute("formatstr") ; 
            var wheresect =parentnode.childNodes[i].getAttribute("wheresect") ; 
                    
            parentNodeId = parentnode.getAttribute("id") ; 
            
            switch (parentnode.childNodes[i].nodeName)    
            { 
              case "cubeid":
                imageopen = cubeopen    ;imageclose = cubeclose ;link = "#" ;break; 
              case "dementionid": 
                imageopen = demention;  imageclose = demention ;
                link ="javascript:drill('" +   nodeId +','+nodeName +"' )"  ;
                break;
             }
            
             
            valuestr  = "'" + nodeId +"'|'" + parentNodeId + "'|"+ nodeName+"|"+ link +"|"+ imageopen +"|" +imageclose ;  
           
            metatree.push(valuestr) ;  
            maketreenode(parentnode.childNodes[i]) ; 
           
        }
       
     }
     
     
     function makeusertree( ) 
     { 
        
         // metadatadoc  =  document.all.metadataxmldso ;   
      
         //  alert(" ") ;
          //metadatadoc  =  parent.parent.frames(2).document.all("metadataDSO") ; 
     
           var cube =  metadatadoc.selectSingleNode("//cubeid[@id='qz.cube_qz01']") ;   // dementionid
          //var cube =  metadatadoc.selectSingleNode("//dementionid[@id='qz.cube_qz01.d_province']") ;    
     
          valuestr ="" ; 
          parentNodeId  = 0 ; 
          
          nodeId   = cube .getAttribute("id") ;
          nodeName = cube .getAttribute("desc") ;
          valuestr  = "'" + nodeId +"'|'" + parentNodeId + "'|"+ nodeName+"|#|"+ cubeopen +"|" +cubeclose ;  
          metatree.push(valuestr) ;       var usernode = findtop( userNodeId  ) ;                // 查找用户id的最上层的id    
          imageopen = demention;  imageclose = demention ;
         
          
          parentNodeId  = nodeId ;       nodeId   = usernode .getAttribute("id") ;
          nodeName = usernode .getAttribute("desc") ; 
          
          var link = " javascript:drill('" +  nodeId +','+nodeName  +"' )"  ;       valuestr  = "'" + nodeId +"'|'" + parentNodeId + "'|"+ nodeName+"|"+ link +"|"+ imageopen +"|" +imageclose ;  
         
          metatree.push(valuestr) ;       maketreenode( usernode) ;  
          //maketreenode(cube ) ;  
          createTree(metatree);    
          
      
     }  
     
     
     function drill(msgstr )    
     {
      var msg = msgstr.split(",") ;    if(confirm("是否要钻取到维度 '" + msg[1] + "' ?" ) ) 
      { 
        window.returnValue = msg[0] ; 
        window.close() ;
      }
      
     }
      
    </script>
    </head><body  >
     
    <xml id="metadataxmldso"  async="false"  src="http://192.1.1.115/WebOlap/metadata.aspx" />  
    <div id="tree">
    <script type="text/javascript">
        makeusertree( ) ; 
    </script>
    </div><input type=button name ="click" value ="clicks" onclick="clickme()" >
    <script language="javascript" > 
     function clickme()
     {
       alert("sds") ;
     }
    </script>
    </body>
    </html>
      

  4.   

    接上
    其中tree.js(网上下的)代码如下:
    / Arrays for nodes and icons
    var nodes = new Array();;
    var openNodes = new Array();
    var icons = new Array(6);// Loads all icons that are used in the tree
    function preloadIcons() {
    icons[0] = new Image();
    icons[0].src = "img/plus.gif";
    icons[1] = new Image();
    icons[1].src = "img/plusbottom.gif";
    icons[2] = new Image();
    icons[2].src = "img/minus.gif";
    icons[3] = new Image();
    icons[3].src = "img/minusbottom.gif";
    icons[4] = new Image();
    icons[4].src = "img/folder.gif";
    icons[5] = new Image();
    icons[5].src = "img/folderopen.gif";
    }
    // Create the tree
    function createTree(arrName, startNode, openNode) {
    nodes = arrName;
    if (nodes.length > 0) {
    preloadIcons();
    if (startNode == null) startNode = 0;
    if (openNode != 0 || openNode != null) setOpenNodes(openNode);
     
          
    if (startNode !=0) {
    var nodeValues = nodes[getArrayId(startNode)].split("|");
    // document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"img/folderopen.gif\" align=\"absbottom\" alt=\"\" />" + nodeValues[2] + "</a><br />");
    document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\"><img src=\"img/"+nodeValues[4].substring(1,nodeValues[4].length -1) +"\" align=\"absbottom\" alt=\"\" />" + nodeValues[2] + "</a><br />");
    } else document.write("<img src=\"img/base.gif\" align=\"absbottom\" alt=\"\" />元数据<br />");

    var recursedNodes = new Array();
    addNode(startNode, recursedNodes);
    }
    }
    // Returns the position of a node in the array
    function getArrayId(node) {
    for (i=0; i<nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[0].substring(1,nodeValues[0].length -1)==node) return i;
    }
    }
    // Puts in array nodes that will be open
    function setOpenNodes(openNode) {
    for (i=0; i<nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[0].substring(1,nodeValues[0].length -1)==openNode) {
    openNodes.push(nodeValues[0].substring(1,nodeValues[0].length -1));
    setOpenNodes(nodeValues[1].substring(1,nodeValues[1].length -1));
    }

    }
    // Checks if a node is open
    function isNodeOpen(node) {
    for (i=0; i<openNodes.length; i++)
    if (openNodes[i]==node) return true;
    return false;
    }
    // Checks if a node has any children
    function hasChildNode(parentNode) {
    for (i=0; i< nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[1].substring(1,nodeValues[1].length -1) == parentNode) return true;
    }
    return false;
    }
    // Checks if a node is the last sibling
    function lastSibling (node, parentNode) { var lastChild = 0;
    for (i=0; i< nodes.length; i++) {
    var nodeValues = nodes[i].split("|");
    if (nodeValues[1].substring(1,nodeValues[1].length -1) == parentNode)
    lastChild = nodeValues[0].substring(1,nodeValues[0].length -1);
    }
    if (lastChild==node) return true;
    return false;
    }
    // Adds a new node to the tree
    function addNode(parentNode, recursedNodes) {
    for (var i = 0; i < nodes.length; i++) { var nodeValues = nodes[i].split("|");
    if (nodeValues[1].substring(1,nodeValues[1].length -1) == parentNode) {

    var ls = lastSibling(nodeValues[0].substring(1,nodeValues[0].length -1), nodeValues[1].substring(1,nodeValues[1].length -1));
    var hcn = hasChildNode(nodeValues[0].substring(1,nodeValues[0].length -1));
    var ino = isNodeOpen(nodeValues[0].substring(1,nodeValues[0].length -1)); // Write out line & empty icons
    for (g=0; g<recursedNodes.length; g++) {
    if (recursedNodes[g] == 1) document.write("<img src=\"img/line.gif\" align=\"absbottom\" alt=\"\" />");
    else  document.write("<img src=\"img/empty.gif\" align=\"absbottom\" alt=\"\" />");
    } // put in array line & empty icons
    if (ls) recursedNodes.push(0);
    else recursedNodes.push(1); // Write out join icons
    if (hcn) {
     
    if (ls) { 

    document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 1,"+ nodeValues[4] +" , "+ nodeValues[5] +");\"><img id=\"join" + nodeValues[0].substring(1,nodeValues[0].length -1) + "\" src=\"img/"); 

      if (ino) document.write("minus");
    else document.write("plus");
    document.write("bottom.gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
    } else {
    document.write("<a href=\"javascript: oc(" + nodeValues[0] + ", 0,"+ nodeValues[4] + ", "+ nodeValues[5]  +");\"><img id=\"join" + nodeValues[0].substring(1,nodeValues[0].length -1) + "\" src=\"img/");

    if (ino) document.write("minus");
    else document.write("plus");
    document.write(".gif\" align=\"absbottom\" alt=\"Open/Close node\" /></a>");
    }
    } else {
    if (ls) document.write("<img src=\"img/join.gif\" align=\"absbottom\" alt=\"\" />");
    else document.write("<img src=\"img/joinbottom.gif\" align=\"absbottom\" alt=\"\" />");
    } // Start link
    document.write("<a href=\"" + nodeValues[3] + "\" onmouseover=\"window.status='" + nodeValues[2] + "';return true;\" onmouseout=\"window.status=' ';return true;\">");

    // Write out folder & page icons
    /*
    if (hcn) {
    document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/folder")
    if (ino) document.write("open");
    document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
    } else document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/page.gif\" align=\"absbottom\" alt=\"Page\" />");
    */
    if (hcn) {
     //document.write("<img id=\"icon" + nodeValues[0] + "\" src=\"img/folder")
     // if (ino) document.write("open");
     //document.write(".gif\" align=\"absbottom\" alt=\"Folder\" />");
     if(ino)  document.write("<img id=\"icon" + nodeValues[0].substring(1,nodeValues[0].length -1) + "\" src=\"img/" + nodeValues[5].substring(1,nodeValues[5].length -1) +"\"" )  
     else 
        document.write("<img id=\"icon" + nodeValues[0].substring(1,nodeValues[0].length -1) + "\" src=\"img/" + nodeValues[5].substring(1,nodeValues[5].length -1) +"\"" )  ;
                                  document.write(" align=\"absbottom\" alt=\"Folder\" />");
    } else document.write("<img id=\"icon" + nodeValues[0].substring(1,nodeValues[0].length -1) + "\" src=\"img/"+nodeValues[4].substring(1,nodeValues[4].length -1) +"\" align=\"absbottom\" alt=\"Page\" />");
     

    // Write out node name
    document.write(nodeValues[2]); // End link
    document.write("</a><br />");

    // If node has children write out divs and go deeper
    if (hcn) {

    //document.write("<div id=\"div" + nodeValues[0] + "\""); 

    document.write("<div id=\"div" + nodeValues[0].substring(1,nodeValues[0].length -1) + "\"");
    if (!ino) document.write(" style=\"display: none;\"");
    document.write(">");
    addNode(nodeValues[0].substring(1,nodeValues[0].length -1), recursedNodes);
    document.write("</div>");
    }

    // remove last line or empty icon 
    recursedNodes.pop();
    }
    }
    }
    // Opens or closes a node
      

  5.   

    接上
    function oc(node, bottom ,closeimage,openimage) {      
    var theDiv = document.getElementById("div" + node );
     
    var theJoin = document.getElementById("join" + node);
    var theIcon = document.getElementById("icon" + node);

     

    if (theDiv.style.display == 'none') {
    if (bottom==1) theJoin.src = icons[3].src;
    else theJoin.src = icons[2].src;
    //theIcon.src = icons[5].src;   

    theIcon.src ="img/" + closeimage   ;  
     
    theDiv.style.display = '';
    } else {
    if (bottom==1) theJoin.src = icons[1].src;
    else theJoin.src = icons[0].src;
    //theIcon.src =  icons[4].src; 
    theIcon.src = "img/"  +openimage   ; 
            
    theDiv.style.display = 'none';


    }
    // Push and pop not implemented in IE(crap!    don磘 know about NS though)
    if(!Array.prototype.push) {
    function array_push() {
    for(var i=0;i<arguments.length;i++)
    this[this.length]=arguments[i];
    return this.length;
    }
    Array.prototype.push = array_push;
    }
    if(!Array.prototype.pop) {
    function array_pop(){
    lastElement = this[this.length-1];
    this.length = Math.max(this.length-1,0);
    return lastElement;
    }
    Array.prototype.pop = array_pop;
    }
    xml文档的格式如下:
    subject desc="主题" id="subject" name="subject">
    - <subjectid desc="求职人员" name="qz" id="qz">
    - <cubeid desc="求职立方体" facttabname="ty_b_qz01" name="cube_qz01" id="qz.cube_qz01">
    - <dementionid desc="省" showcol="tc_b_dq.dqmc" codecol="tc_b_dq.dqbm" showcode="0" fromsect="tc_b_dq,ty_b_qz01" wheresect="tc_b_dq.dqbm=ty_b_qz01.ldbmbh" condition="" name="d_province" id="qz.cube_qz01.d_province" datatype="varchar2(20)" formatstr="text" width="30" usercondition="" valid="true">
      <dementionid desc="市" showcol="tc_b_dq.dqmc" codecol="tc_b_dq.dqbm" showcode="0" fromsect="tc_b_dq,ty_b_qz01" wheresect="tc_b_dq.dqbm=ty_b_qz01.ldbmbh" condition="" name="d_city" id="qz.cube_qz01.d_province.d_city" datatype="varchar2(20)" formatstr="text" width="30" usercondition="" valid="true" /> 
      </dementionid>
    这些文件(包括图片)都放在同一目录下(xml文档的位置放在server下)
      

  6.   

    to HueVan:
       能不能把你测试的资料发我一份,我自己试试看,多谢。
       [email protected]
      

  7.   

    我的代码比csdn的短而且快,因为我数据库设计上有技巧,所以代码短而且简单。
    演示:
    http://www.adr.gov.cn/download/tree/nolimited.asp
    http://www.ymdg.com/tree.htm
    www.adr.gov.cn/download/tree.rar下载原文件
    关于这个问题的争论:
    http://expert.csdn.net/Expert/topic/2442/2442101.xml?temp=6.592959E-02
    阿信的树:
    www.adr.gov.cn/download/deeptree.rar下载原文件