1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

一个树型菜单的JS函数

本帖由 OUYANG2005-11-14 发布。版面名称:前端开发

  1. OUYANG

    OUYANG New Member

    注册:
    2005-09-06
    帖子:
    3,025
    赞:
    5
    <SCRIPT language="JavaScript">
    var lastObj

    function expandIt(obj)
    {
    if(lastObj != null)
    {
    if(obj == lastObj)
    {
    if(obj.style.display == "none")
    {
    obj.style.display = "";
    }
    else
    {
    obj.style.display = "none"
    }
    }
    else
    {
    lastObj.style.display = "none";
    obj.style.display = "";
    }
    }
    else
    {
    obj.style.display = "";
    }

    lastObj = obj
    }
    </SCRIPT>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <%
    dim id
    id = request("id")
    dim strsql,rs

    strsql="select * from p_type where slanguage=1 and typelevel=1 order by typename"
    set rs=fgetrslist(strsql)
    do while not rs.eof

    %>
    <tr>
    <td height="25" class="LEFTLINKS"><img width="30" height="0" align="absmiddle" /><b><%if rs("isleaf")=0 then%><a href="#" onClick="javascript:expandIt(kb<%=rs("id")%>);return false"><%else%><a href="<%=request.ServerVariables("SCRIPT_NAME")%>?idtree=<%=rs("idtree")%>" ><%end if%><%=server.HTMLEncode(right((rs("typename")&""),len(rs("typename")&"")-2))%></a></b></td>
    </tr>
    <%
    IF clng(id)=clng(rs("id")) then

    %>
    <tr id="kb<%=rs("id")%>">
    <%
    else

    %>


    <tr id="kb<%=rs("id")%>" style="display:none;">
    <%
    end if
    %>
    <td>
    <table>
    <%
    dim rs1
    strsql="select * from p_type where parentid="&rs("id")&" and slanguage=1 order by typename"
    set rs1=fgetrslist(strsql)
    do while not rs1.eof
    %>
    <tr><td height="20" class="LEFTLINKS">
    <img width="40" height="0" align="absmiddle" /><a href="<%=request.ServerVariables("SCRIPT_NAME")%>?idtree=<%=rs1("idtree")%>&id=<%=rs("id")%>" ><%=server.HTMLEncode(right((rs1("typename")&""),len(rs1("typename")&"")-2))%></a></td></tr>
    <%
    rs1.movenext
    loop
    rs1.close
    set rs1=nothing
    %>
    </table>
    </td>
    </tr>
    <%
    rs.movenext

    loop
    rs.close
    set rs=nothing
    %>
    </table>