 
- 帖子
- 86
- 积分
- 203
- 体力
- 129 点
- 金币
- 31
- 威望
- 0
|

折叠分类,自动展开当前分类,相信好多朋友都在找,需要的拿到用。
category_tree.js的代码如下:
-
- document.getElementsByClassName = function(cl) {
- var retnode = [];
- var myclass = new RegExp('\\b'+cl+'\\b');
- var elem = this.getElementsByTagName('*');
- for (var j = 0; j < elem.length; j++) {
- var classes = elem[j].className;
- if (myclass.test(classes)) retnode.push(elem[j]);
- }
- return retnode;
- }
-
- function HideAll() {
- var items = document.getElementsByClassName("optiton");
- for (var j=0; j<items.length; j++) {
- items[j].style.display = "none";
- }
- }
-
- function setCookie(sName,sValue,expireHours) {
- var cookieString = sName + "=" + escape(sValue);
- if (expireHours>0) {
- var date = new Date();
- date.setTime(date.getTime + expireHours * 3600 * 1000);
- cookieString = cookieString + "; expire=" + date.toGMTString();
- }
- document.cookie = cookieString;
- }
-
- function getCookie(sName) {
- var aCookie = document.cookie.split("; ");
- for (var j=0; j < aCookie.length; j++){
- var aCrumb = aCookie[j].split("=");
- if (escape(sName) == aCrumb[0])
- return unescape(aCrumb[1]);
- }
- return null;
- }
-
- window.onload = function() {
- var show_item = "opt_1";
- if (getCookie("show_item") != null) {
- show_item= "opt_" + getCookie("show_item");
- }
- document.getElementById(show_item).style.display = "block";
- var items = document.getElementsByClassName("title");
- for (var j=0; j<items.length; j++) {
- items[j].onclick = function() {
- var o = document.getElementById("opt_" + this.name);
- if (o.style.display != "block") {
- HideAll();
- o.style.display = "block";
- setCookie("show_item",this.name);
- }
- else {
- o.style.display = "none";
- }
- }
- }
- }
复制代码
category_tree.lbi 修改如下:
-
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <script type="text/javascript" src="js/category_tree.js"></script>
- <style type="text/css">
- a:link,a:visited {color:#385065;text-decoration:none}
- a:hover {text-decoration:underline}
- #menu {width:150px;margin:0px 15px;padding:0px;text-align:left;list-style:none}
- #menu .item {margin:5px 0px;padding:0px;list-style:none}
- 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}
- #menu .item ul {border:1px solid #9FACB7;margin:0;width:118px;padding:3px 0px 3px 30px;background:#fff;list-style:none;display:none}
- #menu .item ul li {display:block;}
- </style>
-
- <div class="box">
- <ul id="menu">
- <!--{foreach from=$categories item=cat name=cate}-->
- <li class="item"><a href="javascript:void(0)" class="title" name="{$smarty.foreach.cate.iteration}">{$cat.name|escape:html}</a>
- <ul id="opt_{$smarty.foreach.cate.iteration}" class="optiton">
- <!--{foreach from=$cat.cat_id item=child}-->
- <li><a href="{$child.url}">{$child.name|escape:html}</a></li>
- <!--{/foreach}-->
-
- </ul>
- </li>
- <!--{/foreach}-->
- </ul>
- </div>
- <div class="blank5"></div>
-
-
复制代码 |
|