| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2810 人关注过本帖
标题:求助,哪位高手帮我看下这段代码,三级折叠菜单,标题名从数据库读的。
只看楼主 加入收藏
luckystar_t
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2011-6-18
结帖率:66.67%
收藏
已结贴  问题点数:20 回复次数:14 
求助,哪位高手帮我看下这段代码,三级折叠菜单,标题名从数据库读的。
<!--#include file="conn.asp" -->
<html>
<head>
<title></title>
<style>
*,body,ul,li,h1,h2{ margin:0; padding:0; list-style:none;}
body{font:12px "宋体"; padding-top:20px;}
#menu { width:200px; margin:auto;}
    #menu h1 { cursor:pointer; color:#FFF; font-size:12px; padding:5px 0 3px 10px; border:#C60 1px solid; margin-top:1px;  background-color:#F93;}
    #menu h2 { cursor:pointer; color:#777; font-size:12px; padding:5px 0 3px 10px; border:#E7E7E7 1px solid; border-top-color:#FFF; background-color:#F4F4F4;}
    #menu ul { padding-left:15px; height:100px;border:#E7E7E7 1px solid; border-top:none;overflow:auto;}
    #menu ul li {padding:5px 0 3px 10px;}
    .no { display:none;}
</style>
<script language="JavaScript">
<!--//
function ShowMenu(obj,noid){
    var block =    document.getElementById(noid);
    var n = noid.substr(noid.length-1);
    if(noid.length==4){
        var ul = document.getElementById(noid.substring(0,3)).getElementsByTagName("ul");
        var h2 = document.getElementById(noid.substring(0,3)).getElementsByTagName("h2");
        for(var i=0; i<h2.length;i++){
            h2[i].innerHTML = h2[i].innerHTML.replace("+","-");
            h2[i].style.color = "";
        }
        obj.style.color = "#FF0000";
        for(var i=0; i<ul.length; i++){if(i!=n){ul[i].className = "no";}}
    }else{
        var span = document.getElementById("menu").getElementsByTagName("span");
        var h1 = document.getElementById("menu").getElementsByTagName("h1");
        for(var i=0; i<h1.length;i++){
            h1[i].innerHTML = h1[i].innerHTML.replace("+","-");
            h1[i].style.color = "";
        }
        obj.style.color = "#0000FF";
        for(var i=0; i<span.length; i++){if(i!=n){span[i].className = "no";}}
    }
    if(block.className == "no"){
        block.className = "";
        obj.innerHTML = obj.innerHTML.replace("-","+");
    }else{
        block.className = "no";
        obj.style.color = "";
    }
}
//-->
</script>
</head>
<body>
<div id="menu">
<%
set rs_Pro1=server.createobject("adodb.recordset")
sqltext4=" select* from Hope_ProductClassid where parentid=0 and  parentid1=1 order by id desc"
rs_Pro1.open sqltext4,conn,1,1                     
%>            
  <%                                   '一级菜单
  dim m
  m=0
  do while not rs_Pro1.eof
  %>


    <h1 onClick="javascript:ShowMenu(this,'<%=m%>')">- <%=rs_Pro1("classname")%></h1>
    <span id="<%=m%>" class="no">
   

<%
            '2级菜单循环
set rs_Pro2=server.createobject("adodb.recordset")
sqltext4="select * from Hope_ProductClassid where parentid="& rs_Pro1("id") &" order by id desc"
rs_Pro2.open sqltext4,conn,1,1                 
%>   
               <%
               dim x
               x=0
               do while not rs_Pro2.eof
               %>
        <h2 onClick="javascript:ShowMenu(this,'<%=x%>')">- <%=rs_Pro2("classname")%></h2>

                     
        <ul id="<%=x%>" class="no">
                               <%
                                         '3级菜单循环
                              set rs_Pro3=server.createobject("adodb.recordset")
                              sqltext4="select * from Hope_ProductClassid where parentid1="& rs_Pro2("id") &" order by id desc"
                              rs_Pro3.open sqltext4,conn,1,1   
                           do while not rs_Pro3.eof            
                              %>                              
            <li><%=rs_Pro3("classname")%></li>
                              <%
                           rs_Pro3.movenext
                             loop
                           rs_Pro3.close
                          %>
        </ul>
            <%
              x=x+1
              rs_Pro2.movenext
              loop
              rs_Pro2.close
              %>
    </span>
<%
    m=m+1
    rs_Pro1.movenext
    loop
    rs_Pro1.close
%>
</div>
</body>
</html>
sql语句不用看了,是没错滴 我qq1102211065,问题出现在,点击一级标题能弹出二级菜单,点击其他一级菜单刚才菜单能收回去,这点已经达到,但是当点击二级菜单的时候,不能弹出三级菜单,而且被点击的菜单会收回去,求解,困恼了一天了都没看出来问题

[ 本帖最后由 luckystar_t 于 2011-7-8 10:08 编辑 ]
搜索更多相关主题的帖子: 数据库 
2011-07-08 10:00
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:20 
给一下,浏览器查看源代码的内容。

----我怎能在别人的苦难面前转过脸去----
2011-07-08 10:49
luckystar_t
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2011-6-18
收藏
得分:0 

<html>
<head>
<title></title>
<style>
*,body,ul,li,h1,h2{ margin:0; padding:0; list-style:none;}
body{font:12px "宋体"; padding-top:20px;}
#menu { width:200px; margin:auto;}
    #menu h1 { cursor:pointer; color:#FFF; font-size:12px; padding:5px 0 3px 10px; border:#C60 1px solid; margin-top:1px;  background-color:#F93;}
    #menu h2 { cursor:pointer; color:#777; font-size:12px; padding:5px 0 3px 10px; border:#E7E7E7 1px solid; border-top-color:#FFF; background-color:#F4F4F4;}
    #menu ul { padding-left:15px; height:100px;border:#E7E7E7 1px solid; border-top:none;overflow:auto;}
    #menu ul li {padding:5px 0 3px 10px;}
    .no { display:none;}
</style>
<script language="JavaScript">
<!--//
function ShowMenu(obj,noid){
    var block =    document.getElementById(noid);
    var n = noid.substr(noid.length-1);
    if(noid.length==4){
        var ul = document.getElementById(noid.substring(0,3)).getElementsByTagName("ul");
        var h2 = document.getElementById(noid.substring(0,3)).getElementsByTagName("h2");
        for(var i=0; i<h2.length;i++){
            h2[i].innerHTML = h2[i].innerHTML.replace("+","-");
            h2[i].style.color = "";
        }
        obj.style.color = "#FF0000";
        for(var i=0; i<ul.length; i++){if(i!=n){ul[i].className = "no";}}
    }else{
        var span = document.getElementById("menu").getElementsByTagName("span");
        var h1 = document.getElementById("menu").getElementsByTagName("h1");
        for(var i=0; i<h1.length;i++){
            h1[i].innerHTML = h1[i].innerHTML.replace("+","-");
            h1[i].style.color = "";
        }
        obj.style.color = "#0000FF";
        for(var i=0; i<span.length; i++){if(i!=n){span[i].className = "no";}}
    }
    if(block.className == "no"){
        block.className = "";
        obj.innerHTML = obj.innerHTML.replace("-","+");
    }else{
        block.className = "no";
        obj.style.color = "";
    }
}
//-->
</script>
</head>
<body>
<div id="menu">



    <h1 onClick="javascript:ShowMenu(this,'0')">- 台球配件</h1>
    <span id="0" class="no">
   


        <h2 onClick="javascript:ShowMenu(this,'0')">- 台球饰品</h2>

                     
        <ul id="0" class="no">
                              
        </ul>
              
    </span>



    <h1 onClick="javascript:ShowMenu(this,'1')">- 台球桌</h1>
    <span id="1" class="no">
   


        <h2 onClick="javascript:ShowMenu(this,'0')">- 奥得威(OLD WORLD)</h2>

                     
        <ul id="0" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'1')">- 亚力士(AILEEX)</h2>

                     
        <ul id="1" class="no">
                              
        </ul>
              
    </span>



    <h1 onClick="javascript:ShowMenu(this,'2')">- 球杆盒筒</h1>
    <span id="2" class="no">
   


        <h2 onClick="javascript:ShowMenu(this,'0')">- 斯诺克杆盒</h2>

                     
        <ul id="0" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'1')">- 九球杆筒</h2>

                     
        <ul id="1" class="no">
                              
        </ul>
              
    </span>



    <h1 onClick="javascript:ShowMenu(this,'3')">- 美式球杆</h1>
    <span id="3" class="no">
   


        <h2 onClick="javascript:ShowMenu(this,'0')">- 毒药(POISON)</h2>

                     
        <ul id="0" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'1')">- 力国(Licos)</h2>

                     
        <ul id="1" class="no">
                              
        </ul>
              
    </span>



    <h1 onClick="javascript:ShowMenu(this,'4')">- 英式球杆</h1>
    <span id="4" class="no">
   


        <h2 onClick="javascript:ShowMenu(this,'0')">- JOHN PARRIS</h2>

                     
        <ul id="0" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'1')">- MASTER</h2>

                     
        <ul id="1" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'2')">- BS(白沙)</h2>

                     
        <ul id="2" class="no">
                                                         
            <li>二星</li>
                                                         
            <li>一星</li>
                              
        </ul>
              
    </span>

</div>


</body>
</html>
这是查看源文件的内容
2011-07-08 14:06
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
没有第三级的数据,都是空的,当然不能显示了

----我怎能在别人的苦难面前转过脸去----
2011-07-08 14:40
luckystar_t
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2011-6-18
收藏
得分:0 
不是啦,最好个菜单有的,关键是现在点二级菜单它还要缩回去
    <h1 onClick="javascript:ShowMenu(this,'4')">- 英式球杆</h1>
    <span id="4" class="no">
   


        <h2 onClick="javascript:ShowMenu(this,'0')">- JOHN PARRIS</h2>

                     
        <ul id="0" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'1')">- MASTER</h2>

                     
        <ul id="1" class="no">
                              
        </ul>
              
        <h2 onClick="javascript:ShowMenu(this,'2')">- BS(白沙)</h2>

                     
        <ul id="2" class="no">
                                                         
            <li>二星</li>
                                                         
            <li>一星</li>
                              
        </ul>
              
    </span>
2011-07-08 14:53
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
你的菜单的id写的不对,id值有重复了,同时最好不要是纯数字命名
应该如下面的这样:
程序代码:
<h1 onClick="javascript:ShowMenu(this,'m0')">一级菜单</h1>
<span id="m0" class="no">
<h2 onClick="javascript:ShowMenu(this,'m00')">-二级菜单</h2>
<ul id="m00" class="no">
<li>三级菜单</li>
.....
二级菜单 m0, m1, m2
三级菜单 m00, m01, m03...m10, m11....依次
 

----我怎能在别人的苦难面前转过脸去----
2011-07-08 17:17
luckystar_t
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2011-6-18
收藏
得分:0 
<div id="menu">
<%
set rs_Pro1=server.createobject("adodb.recordset")
sqltext4=" select* from Hope_ProductClassid where parentid=0 and  parentid1=1 order by id desc"
rs_Pro1.open sqltext4,conn,1,1                     
%>            
  <%                                   '一级菜单
  dim m
  m="aa"
  do while not rs_Pro1.eof
  %>


    <h1 onClick="javascript:ShowMenu(this,'<%=m%>')">- <%=rs_Pro1("classname")%></h1>
    <span id="<%=m%>" class="no">
   

<%
            '2级菜单循环
set rs_Pro2=server.createobject("adodb.recordset")
sqltext4="select * from Hope_ProductClassid where parentid="& rs_Pro1("id") &" order by id desc"
rs_Pro2.open sqltext4,conn,1,1                 
%>   
               <%
               dim x
               x="bb"
               do while not rs_Pro2.eof
               %>
        <h2 onClick="javascript:ShowMenu(this,'<%=x%>')">- <%=rs_Pro2("classname")%></h2>

                     
        <ul id="<%=x%>" class="no">
                              <%
                           '3级菜单循环
                              set rs_Pro3=server.createobject("adodb.recordset")
                              sqltext4="select * from Hope_ProductClassid where parentid1="& rs_Pro2("id") &" order by id desc"
                              rs_Pro3.open sqltext4,conn,1,1
                              do while not rs_Pro3.eof                     
                              %>                           
            <li><%=rs_Pro3("classname")%></li>
                              <%
                           rs_Pro3.movenext
                           loop
                           rs_Pro3.close
                          %>
        </ul>
              <%  
              x=x+1
              rs_Pro2.movenext
              loop
              rs_Pro2.close
              %>
    </span>
<%
    m=m+1
    rs_Pro1.movenext
    loop
    rs_Pro1.close
%>
</div>
大哥还是不行额,我这里用了你说的方法,用 “字符串”+1的格式来弄应该就不重复啦,还是不行
2011-07-08 17:55
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
楼上的,麻烦你还是把浏览器的源代码发一下,关键的id是什么我还是看不到,你的数据表到底怎么写的?

[ 本帖最后由 dzt0001 于 2011-7-9 08:23 编辑 ]

----我怎能在别人的苦难面前转过脸去----
2011-07-08 23:35
luckystar_t
Rank: 1
等 级:新手上路
帖 子:20
专家分:5
注 册:2011-6-18
收藏
得分:0 
桌面.rar (34.4 KB)
大哥我直接把我的源文件奉上咯- -帮我看看
2011-07-09 10:56
dzt0001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:5
帖 子:1281
专家分:4998
注 册:2005-10-12
收藏
得分:0 
找到你这个CSS折叠菜单的出处了,没搞明白原理前不要乱改

m="aa"改成m=0
<%=m%>改成<%="NO"&m&>

x="bb"改成x=0
<%=x%>改成<%="NO"&m&x>


 
 

[ 本帖最后由 dzt0001 于 2011-7-9 13:02 编辑 ]

----我怎能在别人的苦难面前转过脸去----
2011-07-09 12:43
快速回复:求助,哪位高手帮我看下这段代码,三级折叠菜单,标题名从数据库读的。 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024814 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved