_YI__
2018-08-08 10:50
<!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的其他项在切回“房产“”无显示
用odiv1获取的元素包括了不需要切换的div。
去掉div1和clear两个节点
JavaScript进阶篇
468786 学习 · 22562 问题
相似问题