为了账号安全,请及时绑定邮箱和手机立即绑定

怎么没反应??求解释

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <title>实践题 - 选项卡</title>

    <style type="text/css">

     /* CSS样式制作 */  

     .whole{

         padding:2px;margin:20px;width:280px;height:180px;

         }

     .noe{list-style:none;display: block;height:30px;line-height:30px;border-bottom:2px solid;}

  

     .whole div{   

        position:absolute;

        border-top:solid red;

        border-bottom:solid blue thin;

        border-left:solid blue thin;

        border-right:solid blue thin;

        width:280px;

        height:180px; 

        line-height:20px;

        padding:5px;

        }

     .c{ 

        display:none;

        }

    .whole ul li{

        border:solid red thin;

        border-bottom:none;

        width:60px;

        float:left;

        line-height:28px;

        text-align:center;

        margin:0px 3px;

        display:inline-block;

        cursor:pointer;

    }

    

       

    </style>

    <script type="text/javascript">

    // JS实现选项卡切换

    window.onload=function(){

    var ti=document.getElementsByTagName("whole");

    var te=document.getElementsByTagName("ul").[0];

    var rui=ti.getElementsByTagName("li");

    var du=ti.getElementsByTagName("div");

    for(var i=0;i<rui.length;i++){

        rui[i].index=i;

        rui[i].onclick=function(){

            for(var n=0;n<rui.length;n++){

                rui[n].className="";

                du[n].className="c";               

            }

            this.className="tip";

            du[this.index].className="";

        }

    }

    </script>

 

</head>

<body>

<!-- HTML页面布局 -->


<div>

<ul>

<li>房产</li> 

<li >家居</li>

<li >二手房</li>

</ul>

<div >275万购昌平邻铁三居&nbsp总价20万买一居<br>200万内购五环三居&nbsp140万安家东三环<br>北京首先零首付楼盘&nbsp53万购东5环50平<br>京楼盘直降5000&nbsp中信府&nbsp公园楼王现房</div>



<div>40平出租屋大改造&nbsp美少女混搭小窝<br>经典清新简欧爱家&nbsp90平老房焕发新生<br>新中式的酷色温情&nbsp66平撞色活泼家居<br>瓷砖就像选好老婆&nbsp卫生间烟道的设计</div>



<div>通州豪华3居260万&nbsp二环稀缺2居250W甩<br>西3环通透2居290万&nbsp130万2居限量抢购<br>皇城根小学学区仅260万&nbsp121平270万抛!<br>独家别墅280万&nbsp苏州桥2居优惠价248万</div>

</div>



</body>

</html>


正在回答

1 回答

script标签中写JS代码有问题,你仔细看看,右侧有源码下载可以参考

document.getElementsByTagName("ul").[0];如果你在数组元素中取元素的话,不用点,document.getElementsByTagName("ul").[0];这么写就行

另外for循环没有闭合大括号

whole这是元素名称吗?为什么用getElementsByTagName这个方法去获取?

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
JavaScript进阶篇
  • 参与学习       467065    人
  • 解答问题       21874    个

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

进入课程

怎么没反应??求解释

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信