知识大全 asp无限级分类加js收缩伸展功能代码

Posted

篇首语:宁给好汉拉马,不给懒汉作爷。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 asp无限级分类加js收缩伸展功能代码相关的知识,希望对你有一定的参考价值。

  为了方便使用分类 我定义了一个分类表category 里面字段是

  id(自动编号)  cat_name(分类名) parent_id(父ID 对应本表ID) cat_order(顺序) is_show(是否显示)  u_id(这个用来区别是新闻分类 还是产品分类 还是其他分类) 为了方便 我将这些分类全部放在这张表中

  在给客户添加分类的时候 结果有太多的分类 本来前台显示的时候 将它们全部显示出来了 好长 客户提出修改意见 要求将它们改成点击大分类 才可以将其子分类显示出来 并且每个分类下面还有一条虚线 并且大分类前面有个图片加号 展开后要变成减号

  <script>

  function fd(id num)

  

  t=$( c +id+ _ ) style display;

  if(t== none )

  

  t = block ;

  t = images/fll_ gif ;

  

  else

  

  t = none ;

  t = images/fll_ gif ;

  

  for(i= ;i<=num;i++)

  

  $( c +id+ _ +i) style display=t ;

  $( d_ +id) src=t ;

  

  

  function $(id)

  

  return document getElementById(id);

  

  </script>

  这是asp无限级显示分类代码 并给这些分类加上id

  <%

   功能 asp无限级显示分类+js显示与隐藏

   作者 wangsdong

   开发

   参数 parent_id为父ID stype为新闻 产品 文章大分类

  function cat (parent_id stype)

  set rs =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= order by cat_order asc

  set rs =conn execute(sql)

  If rs eof Then

  Else

  if(depath> ) then

  display = none

  else

  display = block

  end if

  dim j

  j=

  do while not rs eof

  cat_name = rs ( cat_name )

  cat_id = rs ( cat_id )

  parent_id =rs ( parent_id )

   ******************下面是你要显示的******************

  m =

  sql = select count(cat_id) as t from category where parent_id= &cat_id & and u_id= &stype&

  set rs =server createobject( adodb recordset )

  set rs =conn execute(sql )

  if not rs eof then

  m =rs ( t )

  else

  m =

  end if

  rs close

  if(depath<= ) then

  mgif= images/ gif

  a= block

  else

  if(m > ) then

  mgif= images/+ gif

  else

  mgif= images/ gif

  end if

  if(depath= ) then

  a= block

  else

  a= none

  end if

  end if

  catstr=catstr & <tr id= c &parent_id& _ &j& display: &a& ><td width= align= center valign= middle class= dotted_class ><img src= &mgif& width= height= id= d_ &cat_id & ></td><td class= dotted_class leftcatcss >

  if(m > ) then

  catstr=catstr& <a javascript:void( ); _fcksavedurl= javascript:void( ); _fcksavedurl= javascript:void( ); onclick= fd( &cat_id & &m & ) > &vbnewline

  else

  catstr=catstr& <a &cat_id & target= _blank > &vbnewline

  end if

  for i= to depath

  catstr=catstr& &nbsp;

  Next

  catstr=catstr&cat_name & </a></td></tr> &vbnewline

  m =

  sql = select cat_name cat_id from category where parent_id= &parent_id & and u_id= &stype& order by cat_order asc

  set rs =server createobject( adodb recordset )

  set rs =conn execute(sql )

  if not rs eof then

  depath=depath+

  call cat (cat_id stype)

  end if

  rs close

  set rs =nothing

  depath=depath

   ******************上面是你要显示的******************

  j=j+

  rs movenext

  loop

  End If

  rs close

  set rs =nothing

  end Function

  %>

  在使用这个函数之前加上

  catstr=

  然后再call 下面的虚线加在css中的dotted_class里面 这样就搞定了

cha138/Article/program/net/201311/13791

相关参考