ASP's infinite classification plus js shrink and stretch function example code
This example mainly briefly introduces the functions of unlimited classification using ASP and shrinking and stretching using JS.
Before the operation, I defined a classification table category whose fields are
id (automatic number) cat_name (category name) parent_id (parent ID, corresponding to the ID of this table) cat_order (order) is_show (whether to display) u_id (this is used to distinguish whether it is a news category, a product category, or other categories), for convenience , I put all these categories in this table.
When adding categories to customers, there were too many categories. When originally displayed on the front desk, all of them were displayed, which was very long. The customer put forward modification suggestions and requested that they be changed to click on the large category so that its subcategories can be displayed. There is also a dotted line under each category, and there is a picture plus sign in front of the large category, which should become a minus sign after expansion. .
<script>
function fd(id,num)
{
t=$(c+id+_1).style.display;
if(t==none)
{
t1=block;
t2=images/fll_34.gif;
}
else
{
t1=none;
t2=images/fll_34.gif;
}
for(i=1;i<=num;i++)
{
$(c+id+_+i).style.display=t1;
$(d_+id).src=t2;
}
}
function $(id)
{
return document.getElementById(id);
}
</script>
This is the asp unlimited display category code, and adds ids to these categories
<%
'Function: asp unlimited display classification + js display and hide
'Author: wangsdong
'Development: www.aspprogram.cn
'Parameters: parent_id is the parent ID, stype is news, products, and article categories
'Original article, please keep some information when reprinting, thank you
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)
'******************The following is the ****************** you want to display'
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
'******************The above is the ****************** you want to display'
j=j+1
rs1.movenext
loop
End If
rs1.close
set rs1=nothing
end Function
%>
Before using this function add
catstr=
Then call again, and add the following dotted line to dotted_class in css
All functions have been implemented up to this point