选项卡切换内容全没了

来源:10-1 编程挑战

95yzy

2016-08-23 11:47

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>实践题 - 选项卡</title>
    <style type="text/css">
     /* CSS样式制作 */  
        *{ font:12px normal "microsoft yahei";
            padding:0px;
            margin:0px;
        }
        #tabs{ width:290px;
                height:150px;
                padding:5px;
                margin:20px;
               
        }
        #tabs ul{ list-style:none;
                display:block;
                height:30px;
                line-height:30px;
                border-bottom:2px solid saddlebrown;
        }
        #tabs ul li{ background:#fff;
                cursor:pointer;
                float:left;
                list-style:none;
                height:28px;
                line-height:28px;
                margin:0px 3px;
                border:1px solid #aaa;
                border-bottom:none;
                display:inline-block;
                width:60px;
                text-align:center;
        }
        #tabs ul li.on{ border-top:2px solid saddlebrown;
                    border-bottom:2px solid #fff;
        }
        #tabs div{ height:120px;
                line-height:25px;
                border-bottom:1px solid #336699;
                border-top:none;
                border-right:1px solid #336699;
                border-left:1px solid #336699;
                padding:5px;
        }
        .hide{ display:none;}
    </style>
    <script type="text/javascript">
    // JS实现选项卡切换
        window.onload=function(){
            var tabs = document.getElementById('tabs');
            var li = document.getElementsByTagName('li');
            var div = tabs.getElementsByTagName('div');
            for(var i=0; i<li.length; i++){
                li[i].onmouseover = function(){
                    for(var j=0; j<li.length; j++){
                        li[j].className='';
                        div[j].className='hide';
                    }
                this.className="on";
                div[i].className="";
                };
            }
        }
    </script>
 
</head>
<body>
<!-- HTML页面布局 -->
<div id="tabs">
    <ul>
        <li>房产</li>
        <li>家居</li>
        <li>二手房</li>
    </ul>
    <div>
    <p>275万购昌平邻铁三居 总价20万买一居</p>
    <p>200万内购五环三居 140万安家东三环</p>
    <p>北京首现零首付楼盘 53万购东5环50平</p>
    <p>京楼盘直降5000 中信府 公园楼王现房</p>
    </div>
    <div>
    <p>40平出租屋大改造 美少女的混搭小窝</p>
    <p>经典清新简欧爱家 90平老房焕发新生</p>
    <p>新中式的酷色温情 66平撞色活泼家居</p>
    <p>瓷砖就像选好老婆 卫生间烟道的设计</p>
    </div>
    <div>
    <p>通州豪华3居260万 二环稀缺2居250w甩</p>
    <p>西3环通透2居290万 130万2居限量抢购</p>
    <p>黄城根小学学区仅260万 121平70万抛!</p>
    <p>独家别墅280万 苏州桥2居优惠价248万</p>
    </div>
</div>
</body>
</html>


写回答 关注

1回答

  • 那夜淡妆的你
    2016-08-23 16:12:16

    和楼上一样 63 57行错了 出错的时候 多看看代码 一般都是自己粗心

JavaScript进阶篇

本课程从如何插入JS代码开始,带您进入网页动态交互世界

468061 学习 · 21891 问题

查看课程

相似问题