點了li的其他項在切回“房產“”無顯示
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>綜合練習</title>
<style type="text/css">
li {
float: left;
list-style-type: none;
width: 80px;
height: 30px;
/*list-style:none? */
text-align: center;
/*垂直居中*/
line-height: 30px;
margin-right: 2px;
border:1px solid #aaaaaa;
border-bottom:2px saddlebrown solid;
/*cursor 屬性規定要顯示的光標的類型(形狀)。*/
cursor:pointer
}
.on{border-top:2px solid saddlebrown;
border-bottom: 2px solid #fff;
}
.clear{
? ? clear: both; ?
}
.hide{
display: none;
}
#div1{
height:120px;
line-height: 25px;
border:1px solid #336699;
border-top:none;
padding:5px;
width:300px;
padding:5px;
height:150px;
margin:20px;
</style>
<script type="text/javascript">
window.onload=function(){
var odiv1=document.getElementById('div1')
var oUl=odiv1.getElementsByTagName('ul')[0]
var oLi=oUl.getElementsByTagName('li')
var odivs=odiv1.getElementsByTagName('div')
for(var i=0,len=oLi.length;i<len;i++){
oLi[i].index=i;
oLi[i].onclick=function(){
for(var n=0;n<len;n++){
oLi[n].className="";
odivs[n].className="hide"
}
this.className="on";
odivs[this.index].className=""
}
}
}
</script>
</head>
<body>
<div id="div1">
<ul>
<li class="on">房產</li>
<li>家居</li>
<li>二手房</li>
</ul>
<div class="clear"><!--清除浮動--></div>
<div class="kaishi">
275萬購昌平鄰鐵三居 總價20萬買一居<br>?
200萬內購五環三居 140萬安家東三環<br>?
北京首現零首付樓盤 53萬購東5環50平<br>?
京樓盤直降5000 中信府公園樓王現房<br>
</div>
<div class="hide">
40平出租屋大改造 美少女的混搭小窩<br>
? ? ? ? ?經典清新簡歐愛家 90平老房煥發新生<br>?
? ? ? ? ?新中式的酷色溫情 66平撞色活潑家居<br>?
? ? ? ? ?瓷磚就像選好老婆 衛生間煙道的設計<br>
</div>
<div class="hide">
通州豪華3居260萬 二環稀缺2居250w甩<br>?
西3環通透2居290萬 130萬2居限量搶購<br>?
黃城根小學學區僅260萬 121平70萬拋!<br>?
? ? 獨家別墅280萬 蘇州橋2居優惠價248萬<br>
</div>
</div>
</body>
</html>
麻煩大佬看看,點了li的其他項在切回“房產“”無顯示
2018-08-13
用odiv1獲取的元素包括了不需要切換的div。
去掉div1和clear兩個節點