标签实现相册的不同显示

来源:互联网 发布:手机上搞怪的软件 编辑:程序博客网 时间:2024/05/16 14:41

<!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{height:50px;background-color:red;}
#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" onmouseover="show(1)" style="background-color:#093">新闻</li>
     <li id="tab2" onmouseover="show(2)">体育</li>
     <li id="tab3" onmouseover="show(3)">音乐</li>
     <li id="tab4" onmouseover="show(4)">娱乐</li>
  </ul>
</div>
<div id="content">
<p id="p1"><img src="逗死我了.gif"/></p>
<p id="p2" style="display:none;"><img src="meitu_00001.jpg" /></p>
<p id="p3" style="display:none;"><img src="meitu_00002.jpg" /></p>
<p id="p4" style="display:none;"><img src="沧桑了好多.jpg"/></p>
</div>
</div>
</body>
<script>
function show(n){
 for(var i=1;i<=4;i++){
  //先把所有的选项卡背景颜色都设成橙色!内容都隐藏!
  document.getElementById('tab'+i).style.backgroundColor='orange';
  //把所有选项卡都设置一样颜色,并且隐藏下面的div中的文本
  document.getElementById('p'+i).style.display='none'; 
  }
 document.getElementById('tab'+n).style.backgroundColor='green';
 //第一个div设置为green
 document.getElementById('p'+n).style.display='block';
 //通过传递过来的n来设置下面p是否显示 
 }
</script>
</html>