国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

ASP實例教程:asp無限級顯示分類代碼

2024-05-04 11:07:14
字體:
來源:轉載
供稿:網友
為了方便使用分類,我定義了一個分類表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顯示與隱藏
  
  '參數: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&"&nbsp;"
  
  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里面去了。  
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 屯昌县| 宁都县| 泰来县| 佛学| 丹阳市| 高雄市| 凭祥市| 金湖县| 潼关县| 靖西县| 林口县| 盈江县| 包头市| 石屏县| 楚雄市| 方城县| 辽阳县| 阿鲁科尔沁旗| 禄劝| 双桥区| 福鼎市| 高碑店市| 紫阳县| 昌乐县| 曲麻莱县| 都昌县| 冕宁县| 灵石县| 昆山市| 方城县| 休宁县| 米脂县| 阿拉善盟| 泰顺县| 天祝| 柳河县| 恩施市| 呼玛县| 衡阳县| 五指山市| 马山县|