博主信息
博文 25
粉丝 0
评论 0
访问量 24297
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
tab切换3-27
moonheart的博客
原创
835人浏览过

实例

实例
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>javaScript-tab切换-学号:56090</title>
	<style type="text/css">
	*{margin: 0px;padding: 0px;}	
	li{list-style: none;}
	.clear{clear: both;}
	.tab{
		width: 600px;
		height: 300px;
		margin: 50px auto;
	}
	#tab_list{
		height: 40px;
		line-height: 40px;
		text-align: center;
		font-family: '微软雅黑';
		border-bottom: none;
	}
	#tab_list li{
		float: left;
		border: 1px solid #000;
		border-right: none;
		width: 100px;
		border-top-right-radius: 8px;
		border-top-left-radius: 8px;
		z-index: 999;
		cursor: pointer;
	}
	#tab_list li:last-of-type{
		border-right:1px solid #000;
	}
	#tab_content li{
		width: 600px;
		height: 300px;
		border:1px solid #000;
		text-align: center;
		line-height: 300px;
		margin-top: -2px;
	}
	</style>
</head>
<body>
<div class="tab">
	<ul id="tab_list">
		<li onclick="getTab(0);"style="background: #dbd0d6;	border-bottom: none;">tab1</li>
		<li onclick="getTab(1);" style="background: #ccc;">tab2</li>
		<li onclick="getTab(2);" style="background: #ccc;">tab3</li>
		<li onclick="getTab(3);" style="background: #ccc;">tab4</li>		
	</ul>
	<div class="clear"></div>
	<ul id="tab_content">
		<li style="background: #dbd0d6;">我是tab1的内容</li>
		<li style="display: none;background-color: burlywood;">我是tab2的内容</li>
		<li style="display: none;background-color: mediumaquamarine;">我是tab3的内容</li>
		<li style="display: none;background-color: cornflowerblue;">我是tab4的内容</li>		
	</ul>
	<div class="clear"></div>
</div>
<script type="text/javascript">
function getTab(num){
	var colorArr=new Array("#dbd0d6","burlywood","mediumaquamarine","cornflowerblue");
	var tab=document.getElementById('tab_list');
	var tab_list=tab.getElementsByTagName('li');
	var content=document.getElementById('tab_content');
	var content_list=content.getElementsByTagName('li');
	for(var i=0; i<content_list.length;i++){document.getElementById
		content_list[i].style.display="none";
	}tab_content
	content_list[num].style.display="block";
	content_list[num].style.background=colorArr[num];
	for(var i=0;i<tab_list.length;i++){
		tab_list[i].style.background="#ccc";
		tab_list[i].style.borderBottom="1px solid #000";
	}
	tab_list[num].style.background=colorArr[num];
	tab_list[num].style.borderBottom="none";
	//"1px solid "+colorArr[num];
}	
</script>

</body>
</html>
运行实例 »
点击 "运行实例" 按钮查看在线实例

运行实例 »

点击 "运行实例" 按钮查看在线实例

微信截图_20190328135927.png微信截图_20190328135608.png

批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学