asp无限级分类加js收缩伸展功能代码
来源:asp之家 发布时间:2009-12-08 12:25:00
为了方便使用分类,我定义了一个分类表category,里面字段是
id(自动编号) cat_name(分类名) parent_id(父ID,对应本表ID) cat_order(顺序) is_show(是否显示) u_id(这个用来区别是新闻分类,还是产品分类,还是其他分类),为了方便,我将这些分类全部放在这张表中。
在给客户添加分类的时候,结果有太多的分类,本来前台显示的时候,将它们全部显示出来了,好长。客户提出修改意见,要求将它们改成点击大分类,才可以将其子分类显示出来,并且每个分类下面还有一条虚线,并且大分类前面有个图片加号,展开后要变成减号。
<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>
这是asp无限级显示分类代码,并给这些分类加上id
<%
'功能: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);""" onclick=""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里面,这样就搞定了。
注意:这里得到的是一个表格的行,要和其他行放在一起,不要加到td里面去了。
猜你喜欢
- 其实这个东西没什么技术含量,就是给大家提供一个给表格加滚动条的思路。运行代码框<html><head><tit
- <%Dim sc4Json Sub InitScriptControlSet sc
- Server对象提供对服务器上访问的方法和属性.大多数方法和属性是作为实用程序的功能提供的。语法:Server.property|metho
- 原作者:Jason MannInternet Magazine showed that people do not read on the
- Windows客户端业务群产品营销主管斯蒂芬最近在向记者示范Internet Explorer 8 Beta2版浏览器的技术特征时标识,与用
- 建立合理的索引提高SQL Server的性能在应用系统中,尤其在联机事务处理系统中,对数据查询及处理速度已成为衡量应用系统成败的标准。而采用
- 在access中进行时间的比较sql语句很简单,如select * from table where thetime>#\"
- jQuery是一个非常优秀的JavaScript 框架,使用简单灵活,同时还有许多成熟的插件可供选择,它可以帮助你在项目中加入一些非常好的效
- 随着CSS3越来越热,CSS3动画也逐渐受到大家的关注。这次有幸修改淘宝网全站页头,小小地应用了下(详见http://www.taobao.
- 摘要:SELECT 语句可以帮助我们从MySQL中取出数据。SELECT 大概是 SQL 语言中最常用的语句,而且怎样使用它也最为讲究;用它
- 如何在页面错误时向数据库中添加记录?在ASP中,我在页面中添加了On Error Resume Next错误命令,以消除和避免程序错误。现在
- [Q]怎么样查询特殊字符,如通配符%与_ [Q]如何插入单引号到数据库表中 [Q]怎样设置事务一致性 [Q]怎么样利用光标更新数据 [Q]怎
- <% class menusPublic Title, ID, Image, TitleColor, Target, Backgrou
- 1、单个关键字加亮代码: <div id="txt"> 用JS让文章内容指定
- 由于ACCESS本身没有提供在窗体中添加一个命令按钮实现打开通用对话框的控件,所以大家必须通过编写相关的宏才能实现此功能,但是编写出的宏限制
- jQuery之父John Resig写过一篇《Sub-Pixel Problems in CSS》,一个50px宽的div中有4个float
- MS SQL基本语法及实例操作 一:建表并初始化 ============================ create database
- 题目:一个六位数,分别用2,3,4,5,6乘它,得到的五个新数仍是由原数中的六个数字组成,只是位置不同,则此六位数是多少?function
- 1、新建DLL打开VB6-->文件-->新建工程-->选择ActiveX DLL-->确定2、将默认工程、类重命名工
- 今天研究了一下JS的用setAttribute方法实现一个页面两份样式表的效果,具体方法如下:第一步:在连接样式表的元素里定义一个id,例如