menu.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // JavaScript Document
  2. function chengstate(menuid,save)
  3. { //切换节点的开放/关闭
  4. menuobj = eval("item"+menuid);
  5. obj = eval("pr"+menuid);
  6. if(menuobj.style.display == '')
  7. {
  8. menuobj.style.display = 'none';
  9. }else{
  10. menuobj.style.display = '';
  11. }//end if
  12. switch (obj.className)
  13. {
  14. case "menu1":
  15. obj.className = "menu2";
  16. break;
  17. case "menu2":
  18. obj.className = "menu1";
  19. break;
  20. case "menu3":
  21. obj.className = "menu4";
  22. break;
  23. case "menu4":
  24. obj.className = "menu3";
  25. break;
  26. }//end switch
  27. if(save!=false)
  28. {
  29. setupcookie(menuid); //保存状态
  30. }//end if
  31. }//end funciton chengstaut
  32. function setupcookie(menuid)
  33. { //存入cookie 保存节点状态
  34. var menu = new Array();
  35. var menustr = new String();
  36. menuOpen = false;
  37. if(checkCookieExist("menu"))
  38. { //判断是否是是否已经保存过cookie
  39. menustr = getCookie("menu");
  40. //alert(menustr);
  41. if(menustr.length>0)
  42. { //判断menu是否为空,,,否则分解为数组
  43. menu = menustr.split(",");
  44. for(i=0;i<menu.length;i++)
  45. {
  46. if(menu[i]==menuid)
  47. { //如果是打开状态,,,删除记录
  48. menu[i]='';
  49. menuOpen = true;
  50. }//end if
  51. }//end for
  52. if(menuOpen==false)menu[i] = menuid;
  53. }else{
  54. menu[0] = menuid;
  55. }//end if
  56. }else{
  57. menu[0] = menuid;
  58. }//end if
  59. menustr = menu.join(",");
  60. menustr = menustr.replace(",,",",");
  61. if(menustr.substr(menustr.length-1,1)==',')menustr = menustr.substr(0,menustr.length-1); //去掉最后的 ","
  62. if(menustr.substr(0,1)==',')menustr = menustr.substr(1,menustr.length-1); //去掉开始的 ","
  63. saveCookie("menu",menustr,1000);
  64. //alert(menustr);
  65. //deleteCookie("menu");
  66. }//end function setupcookie
  67. function initialize()
  68. { //取得cookie 设置节点的缩放,,初始化菜单状态
  69. var menu = new Array();
  70. var menustr = new String();
  71. if(checkCookieExist("menu"))
  72. { //判断是否是是否已经保存过cookie
  73. menustr = getCookie("menu");
  74. if(menustr.length>0)
  75. { //判断长度是否合法
  76. menu = menustr.split(",");
  77. for(i=0;i<menu.length;i++)
  78. {
  79. if(objExists(menu[i]))
  80. { //验证对象是否存在
  81. chengstate(menu[i],false);
  82. }//end if
  83. }//end for
  84. objExists(99);
  85. }//end if
  86. }//end if
  87. }//end funciton setupstate
  88. function objExists(objid)
  89. { //验证对象是否存在
  90. try
  91. {
  92. obj = eval("item"+objid);
  93. }//end try
  94. catch(obj)
  95. {
  96. return false;
  97. }//end catch
  98. if(typeof(obj)=="object")
  99. {
  100. return true;
  101. }//end if
  102. return false;
  103. }//end function objExists
  104. //--------------------------------------------------↓↓↓↓↓↓↓↓↓↓↓↓ 执行Cookie 操作
  105. function saveCookie(name, value, expires, path, domain, secure)
  106. { // 保存Cookie
  107. var strCookie = name + "=" + value;
  108. if (expires)
  109. { // 计算Cookie的期限, 参数为天数
  110. var curTime = new Date();
  111. curTime.setTime(curTime.getTime() + expires*24*60*60*1000);
  112. strCookie += "; expires=" + curTime.toGMTString();
  113. }//end if
  114. // Cookie的路径
  115. strCookie += (path) ? "; path=" + path : "";
  116. // Cookie的Domain
  117. strCookie += (domain) ? "; domain=" + domain : "";
  118. // 是否需要保密传送,为一个布尔值
  119. strCookie += (secure) ? "; secure" : "";
  120. document.cookie = strCookie;
  121. }//end funciton saveCookie
  122. function getCookie(name)
  123. { // 使用名称参数取得Cookie值, null表示Cookie不存在
  124. var strCookies = document.cookie;
  125. var cookieName = name + "="; // Cookie名称
  126. var valueBegin, valueEnd, value;
  127. // 寻找是否有此Cookie名称
  128. valueBegin = strCookies.indexOf(cookieName);
  129. if (valueBegin == -1) return null; // 没有此Cookie
  130. // 取得值的结尾位置
  131. valueEnd = strCookies.indexOf(";", valueBegin);
  132. if (valueEnd == -1)
  133. valueEnd = strCookies.length; // 最后一个Cookie
  134. // 取得Cookie值
  135. value = strCookies.substring(valueBegin+cookieName.length,valueEnd);
  136. return value;
  137. }//end function getCookie
  138. function checkCookieExist(name)
  139. { // 检查Cookie是否存在
  140. if (getCookie(name))
  141. return true;
  142. else
  143. return false;
  144. }//end function checkCookieExist
  145. function deleteCookie(name, path, domain)
  146. { // 删除Cookie
  147. var strCookie;
  148. // 检查Cookie是否存在
  149. if (checkCookieExist(name))
  150. { // 设置Cookie的期限为己过期
  151. strCookie = name + "=";
  152. strCookie += (path) ? "; path=" + path : "";
  153. strCookie += (domain) ? "; domain=" + domain : "";
  154. strCookie += "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  155. document.cookie = strCookie;
  156. }//end if
  157. }//end function deleteCookie