JS 后台管理菜单

本文介绍了一种基于HTML和CSS的网页布局方案,通过动态创建标签实现内容切换,提升了用户体验。该方案包括顶部菜单栏、左侧导航栏及主要内容区域的设计,并通过JavaScript实现了标签页的动态加载和关闭功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body {
	font-size: 12px;
}
ul, li, h2 {
	margin: 0;
	padding: 0;
}
ul {
	list-style: none;
}
#top {
	width: 900px;
	height: 40px;
	margin: 0 auto;
	background-color: #CCCC00
}
#top h2 {
	width: 150px;
	height: 40px;
	background-color: #99CC00;
	float: left;
	font-size: 14px;
	text-align: center;
	line-height: 40px;
}
#topTags {
	width: 750px;
	height: 40px;
	margin: 0 auto;
	background-color: #CCCC00;
	float: left
}
#topTags ul li {
	float: left;
	width: 100px;
	height: 25px;
	margin-right: 5px;
	display: block;
	text-align: center;
	cursor: pointer;
	padding-top: 15px;
}
#main {
	width: 900px;
	height: 500px;
	margin: 0 auto;
	background-color: #F5F7E6;
}
#leftMenu {
	width: 150px;
	height: 500px;
	background-color: #009900;
	float: left
}
#leftMenu ul {
	margin: 10px;
}
#leftMenu ul li {
	width: 130px;
	height: 30px;
	display: block;
	background: #99CC00;
	cursor: pointer;
	line-height: 30px;
	text-align: center;
	margin-bottom: 5px;
}
#leftMenu ul li a {
	color: #000000;
	text-decoration: none;
}
#content {
	width: 750px;
	height: 500px;
	float: left
}
.content {
	width: 740px;
	height: 490px;
	display: none;
	padding: 5px;
	overflow-y: auto;
	line-height: 30px;
}
#footer {
	width: 900px;
	height: 30px;
	margin: 0 auto;
	background-color: #ccc;
	line-height: 30px;
	text-align: center;
}
.content1 {
	width: 740px;
	height: 490px;
	display: block;
	padding: 5px;
	overflow-y: auto;
	line-height: 30px;
}
</style>
<script type="text/javascript">
window.onload=function(){
	function $(id){return document.getElementById(id)}
	var menu=$("topTags").getElementsByTagName("ul")[0];//顶部菜单容器
	var tags=menu.getElementsByTagName("li");//顶部菜单
	var ck=$("leftMenu").getElementsByTagName("ul")[0].getElementsByTagName("li");//左侧菜单
	var j;
	//点击左侧菜单增加新标签
	for(i=0;i<ck.length;i++){
		ck[i].onclick=function(){
			$("welcome").style.display="none"//欢迎内容隐藏
			clearMenu();
			this.style.background="yellow";
			//循环取得当前索引
			for(j=0;j<8;j++){
				if(this==ck[j]){
					if($("p"+j)==null){
						openNew(j,this.innerHTML);//设置标签显示文字
					}
				clearStyle();
				$("p"+j).style.backgroundColor="yellow";
				clearContent();
				$("c"+j).style.display="block";
				}
			}
			return false;
		}
	}
	//增加或删除标签
	function openNew(id,name){
		var tagMenu=document.createElement("li");
		tagMenu.id="p"+id;
		tagMenu.innerHTML=name+"   "+"<img src='off.gif' style='vertical-align:middle'/>";
		//标签点击事件
		tagMenu.onclick=function(evt){
			clearMenu();
			ck[id].style.background="yellow";
			clearStyle();
			tagMenu.style.backgroundColor="yellow";
			clearContent();
			$("c"+id).style.display="block";
		}
		//标签内关闭图片点击事件
		tagMenu.getElementsByTagName("img")[0].onclick=function(evt){
			evt=(evt)?evt:((window.event)?window.event:null);
			if(evt.stopPropagation){evt.stopPropagation()} //取消opera和Safari冒泡行为;
			this.parentNode.parentNode.removeChild(tagMenu);//删除当前标签
			var color=tagMenu.style.backgroundColor;
			//设置如果关闭一个标签时,让最后一个标签得到焦点
			if(color=="#ffff00"||color=="yellow"){//区别浏览器对颜色解释
				if(tags.length-1>=0){
					clearStyle();
					tags[tags.length-1].style.backgroundColor="yellow";
					clearContent();
					var cc=tags[tags.length-1].id.split("p");
					$("c"+cc[1]).style.display="block";
					clearMenu();
					ck[cc[1]].style.background="yellow";
				}
				else{
					clearContent();
					clearMenu();
					$("welcome").style.display="block";
				}
			}
		}
		menu.appendChild(tagMenu);
	}
	//清除菜单样式
	function clearMenu(){
		for(i=0;i<ck.length;i++){
			ck[i].style.background="#99CC00";
		}
	}
	//清除标签样式
	function clearStyle(){
		for(i=0;i<tags.length;i++){
			menu.getElementsByTagName("li")[i].style.backgroundColor="#FFCC00";
		}
	}
	//清除内容
	function clearContent(){
		for(i=0;i<7;i++){
			$("c"+i).style.display="none";
		}
	}
}
</script>
</head>
<body>
<div id="top">
    <h2>管理菜单</h2>
    <div id="topTags">
        <ul>
        </ul>
    </div>
</div>
<div id="main">
    <div id="leftMenu">
        <ul>
            <li>导航一</li>
            <li>导航二</li>
            <li>导航三</li>
            <li>导航四</li>
            <li>导航五</li>
            <li>导航六</li>
            <li>导航七</li>
        </ul>
    </div>
    <div id="content">
        <div id="welcome" class="content" style="display:block;">
            <div align="center">
                <p> </p>
                <p><strong>欢迎光临</strong></p>
                <p> </p>
            </div>
        </div>
        <div id="c0" class="content"><a href="###">导航一内容</a></div>
        <div id="c1" class="content"><a href="###">导航二内容</a></div>
        <div id="c2" class="content"><a href="###">导航三内容</a></div>
        <div id="c3" class="content"><a href="###">导航四内容</a></div>
        <div id="c4" class="content"><a href="###">导航五内容</a></div>
        <div id="c5" class="content"><a href="###">导航六内容</a></div>
        <div id="c6" class="content"><a href="###">导航七内容</a></div>
    </div>
</div>
<div id="footer">copyright for onestopweb </div>
</body>
</html>

 

效果图:

 

 

 

 

常用的JS后台导航菜单,可刷新不变 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xml:lang="UTF-8" lang="UTF-8"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="UTF-8" /> <title>后台管理</title> <style type="text/css"> body {margin:0;text-align:center;color:#000;font:normal 12px Arial,Verdana,Tahoma;text-align:center;background:#C8D0D5;line-height:150%;} 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:url(http://www.tblog.com.cn/attachments/month_0609/m20069110491.gif) 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> [removed] // --- 获取ClassName 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"; } } // --- 设置cookie 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(); } [removed] = cookieString; } //--- 获取cookie function getCookie(sName) { var aCookie = [removed].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 { 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] { 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"; } } } } [removed] </head> <body> <ul id="menu"> <li class="item"><a href="[removed]void(0)" class="title" name="1">基本信息</a> <ul id="opt_1" class="optiton"> <li><a href="#">企业简介</a></li> <li><a href="#">企业新闻</a></li> </ul> </li> <li class="item"><a href="[removed]void(0)" class="title" name="2">系统管理</a> <ul id="opt_2" class="optiton"> <li><a href="#">企业简介</a></li> <li><a href="#">企业新闻</a></li> </ul> </li> <li class="item"><a href="[removed]void(0)" class="title" name="3">系统管理</a> <ul id="opt_3" class="optiton"> <li><a href="#">会员管理</a></li> <li><a href="#">管理员设置</a></li> <li><a href="#">权限组设置</a></li> <li><a href="#">退出系统</a></li> </ul> </li> </ul> </body> </html> <a href="http://js.alixixi.com/">欢迎访问阿里西西网页特效代码站,js.alixixi.com</a>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值