ECShop H5微商城
ECShop APP商城
ECshop4.0商业授权
ECShop源码全能套餐
ECMall全能套餐(含主机)
ECMall3.0功能定制
ECShop商城小程序
ECShop二开定制
ECShop授权套餐
ECShop装修市场
ECMall基础套餐(PC+H5)
ECMall3.0商业授权
返回列表 发帖

[共享] 折叠分类,自动展开当前分类。

折叠分类,自动展开当前分类,相信好多朋友都在找,需要的拿到用。

category_tree.js的代码如下:


  1.      document.getElementsByClassName = function(cl) {
  2.          var retnode = [];
  3.          var myclass = new RegExp('\\b'+cl+'\\b');
  4.          var elem = this.getElementsByTagName('*');
  5.          for (var j = 0; j < elem.length; j++) {
  6.              var classes = elem[j].className;
  7.              if (myclass.test(classes)) retnode.push(elem[j]);
  8.          }
  9.          return retnode;
  10.      }
  11.    

  12.      function HideAll() {
  13.          var items = document.getElementsByClassName("optiton");
  14.          for (var j=0; j<items.length; j++) {
  15.              items[j].style.display = "none";
  16.          }

  17.      }
  18.    

  19.      function setCookie(sName,sValue,expireHours) {
  20.          var cookieString = sName + "=" + escape(sValue);
  21.          if (expireHours>0) {
  22.               var date = new Date();
  23.               date.setTime(date.getTime + expireHours * 3600 * 1000);
  24.               cookieString = cookieString + "; expire=" + date.toGMTString();
  25.          }
  26.          document.cookie = cookieString;
  27.      }
  28.    
  29.      function getCookie(sName) {
  30.        var aCookie = document.cookie.split("; ");
  31.        for (var j=0; j < aCookie.length; j++){
  32.          var aCrumb = aCookie[j].split("=");
  33.          if (escape(sName) == aCrumb[0])
  34.            return unescape(aCrumb[1]);
  35.        }
  36.        return null;
  37.      }
  38.    
  39.      window.onload = function() {
  40.          var show_item = "opt_1";
  41.          if (getCookie("show_item") != null) {
  42.               show_item= "opt_" + getCookie("show_item");

  43.          }
  44.          document.getElementById(show_item).style.display = "block";
  45.          var items = document.getElementsByClassName("title");
  46.          for (var j=0; j<items.length; j++) {
  47.              items[j].onclick = function() {
  48.                  var o = document.getElementById("opt_" + this.name);
  49.                  if (o.style.display != "block") {
  50.                      HideAll();
  51.                      o.style.display = "block";
  52.                      setCookie("show_item",this.name);
  53.                  }
  54.                  else {
  55.                      o.style.display = "none";
  56.                  }
  57.              }
  58.          }
  59.      }
复制代码


category_tree.lbi 修改如下:

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  2. <script type="text/javascript" src="js/category_tree.js"></script>
  3. <style type="text/css">   
  4.      a:link,a:visited {color:#385065;text-decoration:none}
  5.      a:hover {text-decoration:underline}
  6.      #menu {width:150px;margin:0px 15px;padding:0px;text-align:left;list-style:none}
  7.      #menu .item {margin:5px 0px;padding:0px;list-style:none}
  8.      a.title:link, a.title:visited, a.title:hover {display:block;background: no-repeat;color:#385065;font-weight:bold;padding:2px 0 0 22px;width:128px;line-height:23px;cursor:pointer;text-decoration:none}
  9.      #menu .item ul {border:1px solid #9FACB7;margin:0;width:118px;padding:3px 0px 3px 30px;background:#fff;list-style:none;display:none}
  10.      #menu .item ul li {display:block;}
  11.      </style>
  12.    
  13. <div class="box">
  14. <ul id="menu">
  15. <!--{foreach from=$categories item=cat name=cate}-->
  16. <li class="item"><a href="javascript:void(0)" class="title" name="{$smarty.foreach.cate.iteration}">{$cat.name|escape:html}</a>
  17.     <ul id="opt_{$smarty.foreach.cate.iteration}" class="optiton">
  18.         <!--{foreach from=$cat.cat_id item=child}-->
  19.         <li><a href="{$child.url}">{$child.name|escape:html}</a></li>
  20.         <!--{/foreach}-->
  21.    
  22.     </ul>
  23. </li>
  24. <!--{/foreach}-->
  25. </ul>
  26. </div>
  27. <div class="blank5"></div>

复制代码
ECShop下载                             ECShop4.0商业授权

好东西!!谢谢分享~~~

TOP

支持你!分享!

TOP

有没有演示给看一下。 支持共享

TOP

谢谢!版面一下子清爽许多!支持共享!
ECShop下载                             ECShop4.0商业授权

TOP

支持,谢谢分享
ECShop下载                             ECShop4.0商业授权

TOP

上个效果图看看哪

TOP

返回列表