系列文章索引

作者:webabcd  来源:博客园  发布时间:2007-02-24 17:58  阅读:19538 次  原文链接   [收藏]  

[最后更新:2010.01.30]

var temp, temp2, cookieArray, cookieArray2, cookieCount; function initiate(){ cookieCount = 0; if(document.cookie) { cookieArray = document.cookie.split(";"); cookieArray2 = new Array(); for(i in cookieArray) { cookieArray2[cookieArray[i].split("=")[0].replace(/ /g,"")] = cookieArray[i].split("=")[1].replace(/ /g,""); } } cookieArray = (document.cookie.indexOf("state=") >= 0) ? cookieArray2["state"].split(",") : new Array(); temp = document.getElementById("containerul"); objli = temp.getElementsByTagName("li"); for(var o = 0; o < objli.length; o++){ if(objli[o].getElementsByTagName("ul").length > 0) { temp2 = document.createElement("span"); temp2.className = "symbols"; temp2.style.backgroundImage = (cookieArray.length > 0) ? ((cookieArray[cookieCount] == "true") ? "url(http://images.cnblogs.com/cnblogs_com/webabcd/85449/o_minus.png)" : "url(http://images.cnblogs.com/cnblogs_com/webabcd/85449/o_plus.png)") : "url(http://images.cnblogs.com/cnblogs_com/webabcd/85449/o_plus.png)"; temp2.onclick = function() { showhide(this.parentNode); writeCookie(); } objli[o].insertBefore(temp2, objli[o].firstChild) objli[o].getElementsByTagName("ul")[0].style.display = "none"; if(cookieArray[cookieCount] == "true") { showhide(objli[o]); } cookieCount++; } else { temp2 = document.createElement("span"); temp2.className = "symbols"; temp2.style.backgroundImage = "url(http://images.cnblogs.com/cnblogs_com/webabcd/85449/o_page.png)"; objli[o].insertBefore(temp2, objli[o].firstChild); } } } function showhide(el) { el.getElementsByTagName("ul")[0].style.display=(el.getElementsByTagName("ul")[0].style.display=="block")?"none":"block"; el.getElementsByTagName("span")[0].style.backgroundImage=(el.getElementsByTagName("ul")[0].style.display == "block") ? "url(http://images.cnblogs.com/cnblogs_com/webabcd/85449/o_minus.png)" : "url(http://images.cnblogs.com/cnblogs_com/webabcd/85449/o_plus.png)"; } function writeCookie() { cookieArray = new Array() objli = temp.getElementsByTagName("li"); for(var q = 0; q < objli.length; q++){ if(objli[q].childNodes.length > 0) { if(objli[q].childNodes[0].nodeName == "SPAN" && objli[q].getElementsByTagName("ul").length > 0) { cookieArray[cookieArray.length] = (objli[q].getElementsByTagName("ul")[0].style.display == "block"); } } } document.cookie = "state=" + cookieArray.join(",") + ";expires=" + new Date(new Date().getTime() + 365*24*60*60*1000).toGMTString(); } initiate();

 

posted on 2010-04-20 10:59  l1b2q31  阅读(213)  评论(0编辑  收藏  举报

导航