<% '功能:asp無限級顯示分類+js顯示與隱藏 '作者:wangsdong '開發:www.aspprogram.cn '參數:parent_id為父ID,stype為新聞,產品,文章大分類 '原創文章,轉載請保留些信息,謝謝 function cat111(parent_id,stype) set rs1 =server.createobject("adodb.recordset") sql="select cat_name,cat_id,parent_id from category where parent_id="&parent_id&" and u_id="&stype&" and is_show=1 order by cat_order asc" set rs1=conn.execute(sql) If rs1.eof Then Else if(depath>2) then display2="none" else display2="block" end if dim j j=1 do while not rs1.eof cat_name1 = rs1("cat_name") cat_id1 = rs1("cat_id") parent_id1=rs1("parent_id") '******************下面是你要顯示的******************' m9=0 sql2="select count(cat_id) as t from category where parent_id="&cat_id1&" and u_id="&stype&"" set rs2=server.createobject("adodb.recordset") set rs2=conn.execute(sql2) if not rs2.eof then m9=rs2("t") else m9=0 end if rs2.close
if(depath<=2) then mgif="images/-.gif" a="block" else if(m9>0) then mgif="images/+.gif" else mgif="images/-.gif" end if if(depath=4) then a="block" else a="none" end if end if
catstr=catstr & "<tr id=""c"&parent_id&"_"&j&""" style=""display:"&a&"""><td width=""25"" align=""center"" valign=""middle"" class=""dotted_class""><img src="""&mgif&""" width=""12"" height=""11"" id=""d_"&cat_id1&"""></td><td class=""dotted_class leftcatcss"">" if(m9>0) then catstr=catstr&"<a href=""javascript:void(0);"" _fcksavedurl="""javascript:void(0);""" _fcksavedurl="""javascript:void(0);"""fd("&cat_id1&","&m9&")"">" &vbnewline else catstr=catstr&"<a href=""products.asp?id="&cat_id1&""" target=""_blank"">"&vbnewline end if for i=1 to depath catstr=catstr&" " Next catstr=catstr&cat_name1&"</a></td></tr>"&vbnewline m9=0
sql2="select cat_name,cat_id from category where parent_id="&parent_id1&" and u_id="&stype&" order by cat_order asc" set rs2=server.createobject("adodb.recordset") set rs2=conn.execute(sql2) if not rs2.eof then depath=depath+4 call cat111(cat_id1,stype) end if rs2.close set rs2=nothing depath=depath-4 '******************上面是你要顯示的******************' j=j+1 rs1.movenext loop End If rs1.close set rs1=nothing end Function %> 在使用這個函數之前加上 catstr="" 然后再call,下面的虛線加在css中的dotted_class里面 到這里功能都已經實現了