读书人

选项卡兑现内容的变换

发布时间: 2013-03-01 18:33:02 作者: rapoo

选项卡实现内容的变换

<!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">
*{ margin:0; padding:0; border:0;}
#main{ width:300px;
height:300px;
background-color:#093;
}
#head{ background-color:#F00; height:50px;}
#head li{ float:left; list-style:none;height:50px; width:72px; text-align:center; background-color:#F93; margin-right:3px;}
</style>
</head>

<body>
<div id="main">
<div id="head">
<ul>
<li id="tab1" onmousemove="show(1)" style="background-color:#093">新闻</li>
<li id="tab2" onmousemove="show(2)">体育</li>
<li id="tab3" onmousemove="show(3)">音乐</li>
<li id="tab4" onmousemove="show(4)">娱乐</li>
</ul>
</div>
<div id="content">
<br /><br /><br /><br />
<p id="p1"><font size="+2" color="#CCFF00">今天习总书记去乌干达访问了!</font></p>
<p id="p2" style="display:none;"><font size="+2" color="#CCFF00">乔丹改打乒乓球!</font></p>
<p id="p3" style="display:none;"><font size="+2" color="#CCFF00">江南style风靡一时!</font></p>
<p id="p4" style="display:none;"><font size="+2" color="#CCFF00">赵本山退出春晚!</font></p>
</div>
</div>
</body>
<script>
function show(n){
for(var i=1;i<=4;i++){
//先把所有的选项卡背景颜色都设成橙色!内容都隐藏!
document.getElementById('tab'+i).style.backgroundColor='orange';
document.getElementById('p'+i).style.display='none';
//把所有的选项都统一颜色,同时把选相对应的内容都设置为隐藏
}
document.getElementById('tab'+n).style.backgroundColor='green';
document.getElementById('p'+n).style.display='block';
//通过被选中的选项卡传过来的参数,单个进行头的选项颜色设置,和对性内容display单个设置成block显示出来!
}
</script>
</html>

读书人网 >编程

热点推荐