浪漫部落 - 浪漫森林

标题: 一个简洁的管理菜单 [打印本页]

作者: 2193232    时间: 2008-6-8 23:18
标题: 一个简洁的管理菜单

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>无标题文档</title>
  6. <style type="text/css">
  7. body{font-size:12px;}
  8. ul,li,h2{margin:0;padding:0;}
  9. ul{list-style:none;}
  10. #top{width:900px;height:40px;margin:0 auto;background-color:#CCCC00}
  11. #top h2{width:150px;height:40px;background-color:#99CC00;float:left;font-size:14px;text-align:center;line-height:40px;}
  12. #topTags{width:750px;height:40px;margin:0 auto;background-color:#CCCC00;float:left}
  13. #topTags ul li{float:left;width:100px;height:25px;margin-right:5px;display:block;text-align:center;cursor:pointer;padding-top:15px;}
  14. #main{width:900px;height:500px;margin:0 auto;background-color:#F5F7E6;}
  15. #leftMenu{width:150px;height:500px;background-color:#009900;float:left}
  16. #leftMenu ul{margin:10px;}
  17. #leftMenu ul li{width:130px;height:30px;display:block;background:#99CC00;cursor:pointer;line-height:30px;text-align:center;margin-bottom:5px;}
  18. #leftMenu ul li a{color:#000000;text-decoration:none;}
  19. #content{width:750px;height:500px;float:left}
  20. .content{width:740px;height:490px;display:none;padding:5px;overflow-y:auto;line-height:30px;}
  21. #footer{width:900px;height:30px;margin:0 auto;background-color:#ccc;line-height:30px;text-align:center;}
  22. .content1 {width:740px;height:490px;display:block;padding:5px;overflow-y:auto;line-height:30px;}
  23. </style>
  24. <script type="text/javascript">
  25. window.onload=function(){
  26. function $(id){return document.getElementById(id)}
  27. var menu=$("topTags").getElementsByTagName("ul")[0];//顶部菜单容器
  28. var tags=menu.getElementsByTagName("li");//顶部菜单
  29. var ck=$("leftMenu").getElementsByTagName("ul")[0].getElementsByTagName("li");//左侧菜单
  30. var j;
  31. //点击左侧菜单增加新标签
  32. for(i=0;i<ck.length;i++){
  33. ck[i].onclick=function(){
  34. $("welcome").style.display="none"//欢迎内容隐藏
  35. clearMenu();
  36. this.style.background="yellow";
  37. //循环取得当前索引
  38. for(j=0;j<8;j++){
  39. if(this==ck[j]){
  40. if($("p"+j)==null){
  41. openNew(j,this.innerHTML);//设置标签显示文字
  42. }
  43. clearStyle();
  44. $("p"+j).style.backgroundColor="yellow";
  45. clearContent();
  46. $("c"+j).style.display="block";
  47.    }
  48. }
  49. return false;
  50.   }
  51. }
  52. //增加或删除标签
  53. function openNew(id,name){
  54. var tagMenu=document.createElement("li");
  55. tagMenu.id="p"+id;
  56. tagMenu.innerHTML=name+"   "+"<img src='http://www.tjdadi.com.cn/off.gif' style='vertical-align:middle'/>";
  57. //标签点击事件
  58. tagMenu.onclick=function(evt){
  59. clearMenu();
  60. ck[id].style.background="yellow";
  61. clearStyle();
  62. tagMenu.style.backgroundColor="yellow";
  63. clearContent();
  64. $("c"+id).style.display="block";
  65. }
  66. //标签内关闭图片点击事件
  67. tagMenu.getElementsByTagName("img")[0].onclick=function(evt){
  68. evt=(evt)?evt:((window.event)?window.event:null);
  69. if(evt.stopPropagation){evt.stopPropagation()} //取消opera和Safari冒泡行为;
  70. this.parentNode.parentNode.removeChild(tagMenu);//删除当前标签
  71. var color=tagMenu.style.backgroundColor;
  72. //设置如果关闭一个标签时,让最后一个标签得到焦点
  73. if(color=="#ffff00"||color=="yellow"){//区别浏览器对颜色解释
  74. if(tags.length-1>=0){
  75. clearStyle();
  76. tags[tags.length-1].style.backgroundColor="yellow";
  77. clearContent();
  78. var cc=tags[tags.length-1].id.split("p");
  79. $("c"+cc[1]).style.display="block";
  80. clearMenu();
  81. ck[cc[1]].style.background="yellow";
  82. }
  83. else{
  84. clearContent();
  85. clearMenu();
  86. $("welcome").style.display="block"
  87.    }
  88.   }
  89. }
  90. menu.appendChild(tagMenu);
  91. }
  92. //清除菜单样式
  93. function clearMenu(){
  94. for(i=0;i<ck.length;i++){
  95. ck[i].style.background="#99CC00";
  96. }
  97. }
  98. //清除标签样式
  99. function clearStyle(){
  100. for(i=0;i<tags.length;i++){
  101. menu.getElementsByTagName("li")[i].style.backgroundColor="#FFCC00";
  102.   }
  103. }
  104. //清除内容
  105. function clearContent(){
  106. for(i=0;i<7;i++){
  107. $("c"+i).style.display="none";
  108. }
  109. }
  110. }
  111. </script>
  112. </head>
  113. <body>
  114. <div id="top">
  115. <h2>管理菜单</h2>
  116. <div id="topTags">
  117. <ul>
  118. </ul>
  119. </div>
  120. </div>
  121. <div id="main">
  122. <div id="leftMenu">
  123. <ul>
  124. <li>个人资料</li>
  125. <li>相册管理</li>
  126. <li>日志管理</li>
  127. <li>留言管理</li>
  128. <li>风格管理</li>
  129. <li>系统管理</li>
  130. <li>帮助信息</li>
  131. </ul>
  132. </div>
  133. <div id="content">
  134. <div id="welcome" class="content" style="display:block;">
  135.   <div align="center">
  136.     <p> </p>
  137.     <p><strong>欢迎使用用户管理系统!</strong></p>
  138.     <p> </p>
  139.     </div>
  140. </div>
  141. <div id="c0" class="content">个人资料</div>
  142. <div id="c1" class="content">相册管理</div>
  143. <div id="c2" class="content">日志管理</div>
  144. <div id="c3" class="content">留言管理</div>
  145. <div id="c4" class="content">风格管理</div>
  146. <div id="c5" class="content">系统管理</div>
  147. <div id="c6" class="content">帮助信息</div>
  148. </div>
  149. </div>
  150. <div id="footer">copyright for lalasxc </div>
  151. </body>
  152. </html>
复制代码

作者: ..尐觜亂親}′    时间: 2008-6-9 23:22
什么东西?
作者: 浪漫♀sunny    时间: 2008-6-9 23:48
代码不错,值得学习,LZ辛苦了
页面效果:

                               
登录/注册后可看大图

作者: 斌分o    时间: 2008-11-22 23:29
提示: 作者被禁止或删除 内容自动屏蔽
作者: 浪漫♂娚孜    时间: 2008-11-23 23:26
都是代码··

有没有详细的·说明·
作者: Z-7ay    时间: 2008-11-26 17:51
不知道楼主发这个干什么。有什么用。给大家发下截图看看这段代码。的效果




欢迎光临 浪漫部落 - 浪漫森林 (http://bbs.weet.com.cn/) Powered by Discuz! X3