运用js写的一个小例子,实现点击不同的标签出现不同的内容:
<!DOCTYPE html>
<html>
<head>
<meta chaset="utf-8">
<script>
function nav(obj, x)
{
var a = obj.parentNode.parentNode.children;
for(var i =0;i<a.length;i++) {
a[i].style="border:1px solid red";
}
obj.parentNode.style="border-bottom:white;";
var div = document.getElementsByName("Div");
for(var i =0;i<div.length;i++) {
div[i].style.display="none";
div[x].style.display="";
}
}
</script>
<style>
ul{list-style:none;}
ul li{border: 1px solid red;float:left;padding:10px }
.li{padding:0;width:200px;margin-top:42px}
.active{
border-bottom:white;
}
a{text-decoration:none;}
div{padding:100px}
div h1{text-align:center;}
</style>
</head>
<body>
<ul>
<li class="li"></li>
<li class="active"><a href="#" onclick="nav(this, 0)">导航1</a></li>
<li><a href="#" onclick="nav(this, 1)">导航2</a></li>
<li><a href="#" onclick="nav(this, 2)">导航3</a></li>
<li class="li"></li>
</ul>
<div id="div1" name="Div"><h1>内容1</h1></div>
<div id="div2" name="Div" style="display:none"><h1>内容2</h1></div>
<div id="div3" name="Div" style="display:none"><h1>内容3</h1></div>
</body>
</html>