for (var i=0; i<ar.length; i++){if (ar[i].className=="submenu") 
    ar[i].style.display = "none";
if (i==0)
    ar[i].style.display = "";
}

解决方案 »

  1.   

    楼上的 帅哥  这个不太好使if (document.getElementById){ //Enet.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }上面这段代码在起作用呢改下这个才行 我js 不行 高手指点一下哈
      

  2.   

    if (document.getElementById){ //Enet.com change
    document.write('<style type="text/css">\n')
    document.write('.submenu{display: none;}\n')
    document.write('</style>\n')
    }-------------------
    delete it.
      

  3.   

    不能删除 楼上的帅哥我的意思是在原来的基础上只要加上一个 初始状态 树展开的第一个子节是展开的(display="")  其他子节是隐藏的(display="none")你删除了每个子节都会展开了的
      

  4.   

    你能把你菜单的HTML代码贴出来吗?
      

  5.   

    简单一点吧,把每一个显示的节点都设置为唯一的ID号,
    子ID与父ID有一定的关联,再用javascript去控制每个节点的显示与隐藏;
    类似于:
    <script>
    function showit(id)
    {

    var node = document.getElementById(id);
    var value = node.style.display;
    if (value == 'none')
    {
    node.style.display = "";
    }
    else
    {
    node.style.display = "none";
    }

    }
    </script>
    <BODY>
    <OL>
    <LI onclick="showit('p11');" style="cursor:hand;">1
    <OL id="p11" style="display:none;">
    <LI onclick="showit('pp21');">1-2-1
    <OL id="pp21" style="display:none;">
    <LI>1-2-1-1
    <LI>1-2-1-2
    </OL>
    <LI>1-2-22
    </OL>
    <LI onclick="showit('p21');" style="cursor:hand;">2
    <OL id="p21" style="display:none;">
    <LI>2-1-1
    <LI>2-1-2
    </OL>
    </OL>
    </BODY>
    </HTML>