无法实现效果,有大佬帮忙看一下吗
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>实践题 - 选项卡</title>
<style type="text/css">
/* CSS样式制作 */
*{
margin: 0;
padding: 0;
font-size: 12px;
font-family: "microsoft yahei"
}
#tabs {
float: left;
width: 290px;
height: 150px;
padding: 5px;
margin: 20px;
}
#tabs ul {
display: block;
height: 30px;
border-bottom: 2px solid saddlebrown;
line-height: 30px;
text-align: center;
list-style-type: none;
}
#tabs ul li {
float: left;
display: inline-block;
width: 60px;
height: 28px;
margin: 0 3px;
line-height: 28px;
border: 1px solid #aaa;
border-bottom: none;
cursor: pointer;
}
#tabs div {
height: 110px;
padding:5px;
line-height: 25px;
border: 1px solid #336699;
border-top: none;
}
.hide{
display: none;
}
#tabs ul li.on{
border-top: 2px solid saddlebrown;
border-bottom: 2px solid #fff;
}
</style>
<script type="text/javascript">
// JS实现选项卡切换
window.onload = function(){
var otab = document.getElementById("tabs");
var oul = document.getElementsByTagName("ul")[0];
var oli = oul.getElementsByTagName("li");
var odiv = otab.getElementsByTagName("div");
for (var i = 0; i < oli.length; i++){
oli[i].index = i;
oli.onclick = function(){
for(var i = 0; i < oli.length; i++) {
oli[i].className = "";
}
this.className = "on";
for(var j = 0; j < odiv.length; j++) {
odiv[j].className = "hide";
}
odiv[this.index].className = "";
}
}
}
</script>
</head>
<body>
<!-- HTML页面布局 -->
<div id="tabs">
<ul>
<li class="on">房产</li>
<li>家居</li>
<li>二手房</li>
</ul>
<div>
275万购昌平邻铁三居 总价20万买一居<br>
200万内购五环三居 140万安家东三环<br>
</div>
<div class="hide">
40平出租屋大改造 美少女的混搭小窝<br>
经典清新简欧爱家 90平老房焕发新生<br>
</div>
<div class="hide">
通州豪华3居260万 二环稀缺2居250w甩<br>
西3环通透2居290万 130万2居限量抢购<br>
</div>
</div>
</body>
</html>