麻烦问下各位高手,怎么用javascript写一个树形菜单,树形菜单里的数据是动态的,从数据库得到,我在网上找了很多,但都用不来,希望大家给我一段代码,要有注释,还有JS函数里传递的参数都要解释下,麻烦了,确实是新手,希望各位高手指教,要很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细很详细!!!谢谢

解决方案 »

  1.   

    html标记加写样式用JS动态控制他们就OK了吧.
    那么多免费的自己写多费神还浪费时间精力;并且没有经济效益.
      

  2.   

    再说下:那些事情都是控件大师架构师控件师分析师,CTO,WTO等做的大事情,楼主肯定是做不了的,如果楼主都做了他们器不是什么都不用做了?
    再说了楼主也没拿干那个事情的薪水吧(估计是了),好好劳动
      

  3.   

    你可以这么写树:
    function Node(id, pid, name, url, title, target, icon, iconOpen, open) { this.id = id; this.pid = pid; this.name = name; this.url = url; 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) { this.config = { target : null, folderLinks : true, useSelection : true, useCookies : true, useLines : true, useIcons : true, useStatusText : false, closeSameLevel : false, inOrder : false } this.icon = { root : '../img/root.gif', folder : '../img/folder.gif', folderOpen : '../img/folderopen.gif', node : '../img/node.gif', empty : '../img/empty.gif', line : '../img/line2.gif', join : '../img/join.gif', joinBottom : '../img/joinbottom.gif', plus : '../img/plus.gif', plusBottom : '../img/plusbottom.gif', minus : '../img/minus.gif', minusBottom : '../img/minusbottom.gif', nlPlus : '../img/nolines_plus.gif', nlMinus : '../img/nolines_minus.gif' }; this.obj = objName; this.aNodes = []; this.aIndent = []; this.root = new Node(-1); this.selectedNode = null; this.selectedFound = false; this.completed = false;};
    这是定义的一部分,其他的你自己来定义,加进去就好了。需要动态的话,定义一个div,用innnerHtml输出,转成字符串后,读出来的东西加进去就好了。
      

  4.   

    根节点id,就触发一个js事件,ajax请求子节点数据,之后绑定到第二级菜单
    http://www.open-open.com/ajax/ajax20080531234600.htm
      

  5.   

    不会啊!存在!http://www.open-open.com/ajax/ajax20080531234600.htm
      

  6.   

    我也正在学这个,树是出来了,但是还有一个问题,我想在鼠标点到最底层子节点时,鼠标点击出现一个小窗口。<a href="javascript:open();">登陆</a><div id="login" >
       <span><h1>请选择查询日期(年月日)</h1></span>
    <div id="panel">
       <br />
    报告日期:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<lable>年 </lable><input type="text" style="width: 40px; height: 12px" />
    <lable>月</lable><input type="yue" style="width: 24px; height: 12px">
    <lable>日</lable><input type="yue" style="width: 24px; height: 12px"></div>
    <div id="pane2">
        <br />
    报告日期(选择F1帮助):&nbsp;<lable>年 </lable><input type="text" style="width: 40px; height: 12px" />
    <lable>月</lable><input type="yue" style="width: 24px; height: 12px">
    <lable>日</lable><input type="yue" style="width: 24px; height: 12px"></div>
        <br />
        <br />
    <input  type="checkbox" /><lable>登陆</lable>
         
                               <input type="button" value="提交" />
    &nbsp; &nbsp; &nbsp; &nbsp;<input type="button" value="取消" /><a href="javascript:close();">关闭</a>  
    这是我的小窗口代码,但是我不知道怎么套到根节点去???
      

  7.   

    http://download.csdn.net/source/337273611个Javascript树形菜单
    http://paranimage.com/11-javascript-tree-menus/