ASP实例教程:asp无限级显示分类代码
发布时间:2019-04-13浏览次数:1058
<p>
</p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0"><tbody><tr>
<td style="WORD-WRAP: break-word" bgcolor="#fdfddf">
<font color="#ff0000">WebjxCom提示:</font><font color="#000000">asp无限级分类加js收缩伸展功能代码.</font>
</td>
</tr></tbody></table>
为了方便使用分类,我定义了一个分类表category,里面字段是<br>id(自动编号)  cat_name(分类名) parent_id(父ID,对应本表ID) cat_order(顺序) is_show(是否显示)  u_id(这个用来区别是新闻分类,还是产品分类,还是其他分类),为了方便,我将这些分类全部放在这张表中。<br>在给客户添加分类的时候,结果有太多的分类,本来前台显示的时候,将它们全部显示出来了,好长。客户提出修改意见,要求将它们改成点击大分类,才可以将其子分类显示出来,并且每个分类下面还有一条虚线,并且大分类前面有个图片加号,展开后要变成减号。<br><script><br>function fd(id,num)<br>{<br> t=$("c"+id+"_1").style.display;<br> <br> if(t=="none")<br> {<br>   t1="block";<br>   t2="images/fll_34.gif";<br> }<br> else <br> {<br>  t1="none"; <br>  t2="images/fll_34.gif";<br> }<br> for(i=1;i<=num;i++)<br> {<br>  $("c"+id+"_"+i).style.display=t1;<br>  $("d_"+id).src=t2;  <br> }<br>}<br>function $(id)<br>{<br> return document.getElementById(id);<br>}<br></script><br>这是asp无限级显示分类代码,并给这些分类加上id<br><br><%<br>'功能:asp无限级显示分类+js显示与隐藏<br>'参数:parent_id为父ID,stype为新闻,产品,文章大分类<br>'原创文章,转载请保留些信息,谢谢<br>function cat111(parent_id,stype)<br>set rs1 =server.createobject("adodb.recordset")<br>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"<br>set rs1=conn.execute(sql)<br>If rs1.eof Then<br>Else <br>if(depath>2) then<br> display2="none"     <br>else<br> display2="block" <br>end if  <br>dim j<br>j=1<br>do while not rs1.eof <br> cat_name1 = rs1("cat_name")<br> cat_id1 = rs1("cat_id")  <br> parent_id1=rs1("parent_id") <br> '******************下面是你要显示的******************' <br> m9=0<br> sql2="select count(cat_id) as t from category where parent_id="&cat_id1&" and u_id="&stype&""    <br> set rs2=server.createobject("adodb.recordset")<br> set rs2=conn.execute(sql2) <br> if not rs2.eof then<br>    m9=rs2("t")<br> else<br>  m9=0  <br> end if <br> rs2.close<br>  <br> if(depath<=2) then  <br>  mgif="images/-.gif"<br>  a="block"<br> else<br>  if(m9>0) then <br>  mgif="images/+.gif" <br>  else<br>  mgif="images/-.gif"<br>  end if<br>  if(depath=4) then<br>   a="block"<br>  else  <br>   a="none"<br>  end if<br> end if  <br> <br> <br> 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"">"<br> if(m9>0) then<br>  catstr=catstr&"<a href=""javascript:void(0);"" _fcksavedurl="""javascript:void(0);""" _fcksavedurl="""javascript:void(0);""" onclick=""fd("&cat_id1&","&m9&")"">" &vbnewline<br> else<br>  catstr=catstr&"<a href=""products.asp?id="&cat_id1&""" target=""_blank"">"&vbnewline<br> end if<br> for i=1 to depath<br>   catstr=catstr&"&nbsp;"<br> Next<br> catstr=catstr&cat_name1&"</a></td></tr>"&vbnewline<br> m9=0<br>     <br> sql2="select cat_name,cat_id from category where parent_id="&parent_id1&" and u_id="&stype&" order by cat_order asc"    <br> set rs2=server.createobject("adodb.recordset")<br> set rs2=conn.execute(sql2)<br> if not rs2.eof then<br>    depath=depath+4  <br>    call cat111(cat_id1,stype)<br> end if<br> rs2.close <br> set rs2=nothing <br> depath=depath-4 <br> '******************上面是你要显示的******************'<br> j=j+1<br>rs1.movenext<br>loop<br>End If<br>rs1.close<br>set rs1=nothing<br>end Function<br>%><br>在使用这个函数之前加上<br>catstr=""<br>然后再call,下面的虚线加在css中的dotted_class里面,这样就搞定了。<br>注意:这里得到的是一个表格的行,要和其他行放在一起,不要加到td里面去了。