本帖最后由 yollxt 于 2009-08-10 14:54:07 编辑

解决方案 »

  1.   

    <script>
    var level = 5;
    var n = level;//判断该对象是否包含于side_menu中
    function isInSideMenu(obj){
    if(n){ n--;
    if(obj.getAttribute&&obj.getAttribute("id")=="side_menu"){n = level;return true;}
    if(obj.nodeType==9){n = level;return false;}//超过当前文档树结构时返回false
    else{return isInSideMenu(obj.parentNode);}
    }
    n = level;
    return false;
    }
    //菜单折叠效果函数
    function foldMenu(){
    if(this.nextSibling&&this.nextSibling.nextSibling){
    if(this.nextSibling.nextSibling.style.display=="block"){
    this.nextSibling.nextSibling.style.display ="block";
    this.innerHTML = this.innerHTML.replace("-","+");
    }else{
    this.nextSibling.nextSibling.style.display ="block";
    this.innerHTML = this.innerHTML.replace("+","-");
    }
    }else{
    this.innerHTML = this.innerHTML.replace("+","-");
    }
    }
    //初始化树状菜单
    function intSideMenu(){
    var as = document.getElementsByTagName("a");
    var uls = document.getElementsByTagName("ul");
    var sidemenuUL = document.getElementById("side_menu");
    for(var i=0;i<as.length;i++){
    if(isInSideMenu(as[i])){
    as[i].onclick= foldMenu;
    as[i].innerHTML = as[i].innerHTML.replace("-","+");
    }
    }//给所有树状菜单内的a绑定foldMenu函数
    for(var j=0;j<uls.length;j++){
    if(isInSideMenu(uls[j]))uls[j].style.display ="none";//初始化隐藏树状菜单
    }
    sidemenuUL.style.display = "block";//显示根菜单
    }
    window.onload=function(){
      intSideMenu();
    }
    </script>
    <ul id="side_menu">
    <li style=" background-color:#CCC; margin-top:5px;"><a href="#"> <strong>新品展示</strong></a>
    <ul style='display:none'>
       <li style=" margin-left:5px; background-color:#eee;"><a href="#"> 新品展示</a>
        <ul style='display:none'>
        <li style=" margin-left:4px; background-color:#fff;"><span style=" margin-top:3px; width:190px;display:block; border:#eee solid 1px;"><a href="ProShow.asp?ProId=294"> 高压开关机械特性测试仪  HMGKC-10</a></span></li>
        <li style=" margin-left:4px; background-color:#fff;"><span style=" margin-top:3px; width:190px;display:block; border:#eee solid 1px;"><a href="ProShow.asp?ProId=293"> 配电网电容电流测试仪HMPD-500P</a></span></li>
        <li style=" margin-left:4px; background-color:#fff;"><span style=" margin-top:3px; width:190px;display:block; border:#eee solid 1px;"><a href="ProShow.asp?ProId=259"> SF6密度综合测试仪HM-60ISASF6</a></span></li>
        <li style=" margin-left:4px; background-color:#fff;"><span style=" margin-top:3px; width:190px;display:block; border:#eee solid 1px;"><a href="ProShow.asp?ProId=222"> 柱上真空断路器ZW20A-12型</a></span></li>
        </ul>
       </li>
    </ul>
    </li>
    </ul>
      

  2.   


    function foldMenu(){
    if(this.nextSibling&&this.nextSibling.nextSibling){
    //if(this.nextSibling.nextSibling.style.display=="block"){
    // this.nextSibling.nextSibling.style.display ="none";
    // this.innerHTML = this.innerHTML.replace("-","+");
    //}else{
    this.nextSibling.nextSibling.style.display ="block";
    this.innerHTML = this.innerHTML.replace("+","-");
    // }
    }else{
    this.innerHTML = this.innerHTML.replace("+","-");
    }
    }