老师,我不知道动了哪里,改不回来。能帮我看看吗?

老师,我不知道动了哪里,改不回来。能帮我看看吗?

html 文件

------------------------------

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

    <link rel="stylesheet" type="text/css" href="csspra/csspra.css">

</head>

<body>

    <div class="main" id="main">

        <!--内容-->

        <div class="sub-menu hide" id="sub-menu">

            <div class="inner-box">   

                <div class="sub-inner-box">

                    <div class="title ">手机、配件</div>

                    <div class="sub-row">

                        <span class="bold mr10">手机通讯:</span>

                        <a href="">手机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">手机维修</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">以旧换新</a>

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">手机配件:</span>

                        <a href="">手机壳</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">手机储存卡</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">数据线</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">充电器</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">电池</a>

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">运营商:</span>

                        <a href="">中国联通</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">中国移动</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">中国电信</a>

                    </div>

                    <div class="sub-row">

                    <span class="bold mr10">智能设备:</span>

                    <a href="">智能手环</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">智能家居</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">智能手表</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">其他</a>

                    

                </div>

                    <div class="sub-row">

                        <span class="bold mr10">娱乐:</span>

                        <a href="">耳机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">音响</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">收音机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">麦克风</a>

                    </div>

                </div>

            </div>

                <div class="inner-box">    

                <div class="sub-inner-box">

                    <div class="title ">电脑</div>

                    <div class="sub-row">

                        <span class="bold mr10">电脑:</span>

                        <a href="">笔记本</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">平板</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">一体机</a>

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">电脑配件:</span>

                        <a href="">显示屏</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">CPU</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">主板</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">硬盘</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">电源</a>

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">游戏设备:</span>

                        <a href="">游戏机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">耳机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">游戏软件</a>

                    </div>

                    <div class="sub-row">

                    <span class="bold mr10">网络产品:</span>

                    <a href="">路由器</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">网络机顶盒</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">交换机</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">存储卡</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">网卡</a>

                </div>

                    <div class="sub-row">

                        <span class="bold mr10">外部产品:</span>

                        <a href="">鼠标</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">键盘</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">u盘</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">移动硬盘</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">鼠标垫</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">电脑清洁</a>

                    </div>

                </div>

            </div>

                <div class="inner-box">

                <div class="sub-inner-box">

                    <div class="title ">家用电器</div>

                    <div class="sub-row">

                        <span class="bold mr10">电视:</span>

                        <a href="">国产品牌</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">韩国品牌</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">欧美品牌</a>

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">空调:</span>

                        <a href="">显示器</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">柜式</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">中央</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">挂壁式</a>

                        

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">冰箱:</span>

                        <a href="">多门</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">对门开</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">三门</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">双门</a>

                    </div>

                    <div class="sub-row">

                    <span class="bold mr10">洗衣机:</span>

                    <a href="">滚筒式洗衣机</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">迷你洗衣机</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">洗烘一体机</a>

                    

                </div>

                    <div class="sub-row">

                        <span>厨房电器:</span>

                        <a href="">抽油机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">洗碗机</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">燃气炉</a>

                        

                    </div>

                </div>

            </div>

                <div class="inner-box"></div>

                <div class="sub-inner-box">

                    <div class="title ">家具</div>

                    <div class="sub-row">

                        <span class="bold mr10">家纺:</span>

                        <a href="">被子</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">枕头</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">四件套</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">床垫</a>

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">灯具:</span>

                        <a href="">台灯</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">顶灯</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">节能灯</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">应急灯</a>

                        

                    </div>

                    <div class="sub-row">

                        <span class="bold mr10">厨具:</span>

                        <a href="">烹饪锅具</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">餐具</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">菜板刀具</a>

                        

                    </div>

                    <div class="sub-row">

                    <span class="bold mr10">家装:</span>

                    <a href="">地毯</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">沙发垫套</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">装饰字画</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">照片墙</a>

                    <span class=" mr10 ml10">/</span>

                    <a href="">窗帘</a>

                    

                </div>

                    <div class="sub-row">

                        <span>生活用品:</span>

                        <a href="">收纳用品</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">浴室用品</a>

                        <span class=" mr10 ml10">/</span>

                        <a href="">雨伞雨衣</a> 

                    </div>

                </div>

            </div>

            </div>

        </div>

        <!--主菜单-->

        <div class="menu-box" id="menu-box" ></div>

        <div class="menu-content" id="menu-content">

            <div class="menu-item">

                <a href="">

                <span>手机配件</span>

            <i class="icon">&#xe665;</i></a>

            </div>

            <div class="menu-item">

                <a href="">

                <span>电脑</span>

            <i class="icon">&#xe665;</i></a>

            </div>

            <div class="menu-item">

                <a href="">

                <span>家用电器</span>

            <i class="icon">&#xe665;</i></a>

            </div>

            <div class="menu-item">

                <a href="">

                <span>家具</span>

            <i class="icon">&#xe665;</i></a>

            </div>


        </div>


        <!--banner图-->

   <div class="banner" id="banner">

       <a href="">

       <div class="banner-slide slide1 slide-active"></div>

       </a>

       <a href="">

       <div class="banner-slide slide2"></div></a>

       <a href="">

       <div class="banner-slide slide3"></div></a>

       </div>


       <a href="javascript:void(0)" class="button prev" id="prev"></a>

       <a href="javascript:void(0)" class="button next" id="next"></a>


       <div class="dots" id="dots">

       <span class="active"></span>

       <span></span>

       <span></span></div>


</div>

<script  src="../practice/js/jspra.js"></script>

</body>

</html>

---------------------------

css文件

----------------------------

*{margin: 0;

padding: 0;}

body{

    font-family: 微软雅黑;

    color: #14191e;

}

a{text-decoration: none;}

a:link,a:visited{color:#5e5e5e;}

.main{width: 1200px;height:460px;margin: auto;overflow:hidden;position:relative;}


@font-face{font-family:'iconfont';

src: url(../img/font/iconfont.eot);

scr:url(../img/font/iconfont.eot) format('embedded-opentype');

src: url(../img/font/iconfont.svg) format('svg');

src: url(../img/font/iconfont.ttf) format('truetype');

src: url(../img/font/iconfont.woff) format('woff');

}

/*banner图*/

.banner{width: 1200px;height:460px;margin: auto;overflow:hidden;}

.slide-active{display:block;}

.banner-slide{width: 1200px;height:460px;float: left;display: none;}

.slide1{background:url(../img/bg1.jpg) no-repeat;display: block;}

.slide2{background:url(../img/bg2.jpg) no-repeat;}

.slide3{background:url(../img/bg3.jpg) no-repeat;}

.button{

height:80px;

width:40px;

position:absolute;

top:50%;

left: 244px;

margin-top:-40px;

background:url(../img/arrow.png)  center center no-repeat;

transform:rotate(180deg);

;}

.button:hover{background-color: #333;}

.next{

left:auto;

right:0;

transform:rotate(0deg);}

.dots{

    position:absolute;

    bottom: 24px;

    right:0;

    text-align:right;

    padding-right:24px;

    

}

.dots span{

display: inline-block;

width:12px;

height:12px;

border-radius:50% ;

box-shadow:0 0 0 2px rgba(255,255,255,0.8) inset;

background-color:rgba(7,17,27,0.4);

cursor:pointer;

margin-left:8px

}


.dots span.active{

    background-color: #ffffff;

    box-shadow:0 0 0 2px rgba(7,17,27,0.4) inset;

}

/*菜单*/

.menu-box{

    width: 244px;

    height:460px;

    position:absolute;

    top:0;

    left:0;

    background-color: rgba(7, 17, 27, 0.5);

    opacity:0.5 ;

    z-index:1

}

/*主菜单*/

.menu-content{width:244px;

height:460px;

position:absolute;

top:0;

left:0;

z-index:2;


}



.menu-item{height:64px;

line-height: 66px;

cursor:pointer;

padding:0 24px;

position: relative;


}

.menu-item a{

font-size:16px;

display: block;

color:#fff;

border-bottom:1px rgba(255,255,255,0.4) solid;height:63px;padding:0px 8px;}


.menu-item :last-child a{border-bottom:none;}


.menu-item i{

    position:absolute;

    top:2px;

    right:32px;

    font-family:'iconfont';

    font-size: 24px;

    font-weight: normal;

    font-style: normal;

    color:rgba(255,255,255,0.5)

}

.sub-menu{

position:absolute;

top:0;

left:244px;

border:1px solid #d9dde1;

box-shadow:0 4px 8px 0px rgba(0, 0, 0, 0.1);

background:#fff;

width: 730px;

height: 458px;

z-index: 581;


}

.hide{display: none;}

.inner-box{width:100%;

    height:100%;

    background:url(../img/fe.png) no-repeat;

    display: none;

}

.sub-inner-box{width:652px;

margin-left:40px;

overflow: hidden;

}


.title{font-size:16px;

color:#f01414 ;

margin:20px 0 30px 0px ;

font-weight: bold;

line-height: 16px;

}

.sub-row {margin-bottom: 25px;}

.bold{font-weight:700px;}

.mr{margin-right:10px;}

.ml{margin-left:10px;}

-------------------------------------

js 文件

-----------------------------------------

var index=0,

prev=byId("prev"),

next=byId('next'),

pics=byId('banner').getElementsByTagName('div'),

size=pics.length,

dots=byId('dots').getElementsByTagName('span'),

timer=null,

main=byId("main"),

mainBox=byId("main-box"),

menuItem=byId("menu-content").getElementsByTagName("div"),

subMenu=byId("sub-menu");



//封装获取id的方法

function byId(id){return typeof(id)==="string"?document.getElementById(id):id}

//封装一个ie和非ie浏览器通用的方法


function addHandler(element,type,handler){

    //非ie浏览器

    if(element.addEventListener){element.addEventListener(type,handler,true);}

    else if(element.attachEvent){element.attachEvent("on"+type,handler);}else{element[type]=handler;}}



function changeImg(){

        for(var i=0 ;i<size;i++){

        pics[i].style.display="none";

        dots[i].className="";

    }

    pics[index].style.display="block";

    dots[index].className="active";}


//next按钮播放下一张图片


addHandler(next,"click",function(){

    index++;

    if(index>=size){index=0;}

    changeImg();

})

//next按钮播放上一张图片

addHandler(prev,"click",function(){

    index--;

    if(index<=0){index=size-1;}

    changeImg();

})


//点击原点

for(d=0;d<size;d++){

    dots[d].setAttribute("dis",d);

    addHandler(dots[d],'click',function(){

        index=this.getAttribute("dis");

        changeImg();

    })

}

//定时器

function startAutoPlay(){

    timer=setInterval(function(){index++;if(index>=size){index=0;};changeImg()},3000)

}

//清除定时器

function stopAutoPlay(){

    if(timer){

        clearInterval(timer);

    }

}


addHandler(main,"mouseover",stopAutoPlay);

addHandler(main,"mouseout",startAutoPlay);

startAutoPlay();


for(mlen=0;mlen<menuItem.length;mlen++){

    menuItem[mlen].setAttribute("date-item",mlen);

    addHandler(menuItem[mlen],"mouseover",function(){

        subMenu.className="sub-menu";

        var idx=this.getAttribute('sub-menu');


        for(var m=0;m<menuItem.length;m++){

            subMenu[m].style.display="none";menuItem[m].style.background = "none";

        }

        subItem[idx].style.display="block";

        menuItem[idx].style.background = "rgba(0,0,0,0.1)";

    })

    

}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
好帮手慕言 2020-06-20 10:00:44

同学你好,遇到问题不要慌,先打开控制台(以谷歌为例,可以按F12),

1、在鼠标移入主菜单时,控制台有报错,如下:(报错的行数可能不准确,但也八九不离十了)

http://img1.sycdn.imooc.com//climg/5eed6abe09ffc9f419130215.jpg

出现这种报错,一般是因为元素获取的有问题。显示隐藏的应该时类名为inner-box的元素,因此先获取元素

http://img1.sycdn.imooc.com//climg/5eed6c41099c9b4b08390046.jpg

2、修改 之后还是有和上方相同会报错,那么很有可能就是索引的问题,打印索引发现为null

http://img1.sycdn.imooc.com//climg/5eed6c8c096c0ba005900067.jpg

控制台:
http://img1.sycdn.imooc.com//climg/5eed6c9c09d9626804570164.jpg

现在就可以确定是索引的问题,可以修改如下:

http://img1.sycdn.imooc.com//climg/5eed6cfe0918b70107440174.jpg

3、老师使用的是subItems哦,同学可以仔细看第一条。

html写错控制台不会报错,可以在html文件中慢慢查找问题。

同学可以 把遇到的问题都做一个总结,以后再遇到类似的报错就可以快速解决啦。

祝学习愉快~

  • 提问者 慕用6222994 #1
    按照老师方法,我终于学会怎么发现错误,并且改回了。感谢
    2020-06-20 18:31:44
好帮手慕言 2020-06-19 15:26:39

同学你好,有以下问题

1、代码中多了两个div的闭合标签,去掉即可。如下:

http://img1.sycdn.imooc.com//climg/5eec64620982020007570434.jpg

2、最后一个sub-inner-box要放在inner-box里,嵌套如下:

http://img1.sycdn.imooc.com//climg/5eec6629094669b005630148.jpg

3、获取元素

http://img1.sycdn.imooc.com//climg/5eec687509d0c47308540082.jpg

idx获取的有问题,具体操作如下:

http://img1.sycdn.imooc.com//climg/5eec6890094840ba07830425.jpg

如果我的回答帮到了你,欢迎采纳,祝学习愉快~

  • 提问者 慕用6222994 #1
    老师,我看半天越看越懵逼,你是怎么发现问题的?能详细分享吗?
    2020-06-19 20:38:11
  • 提问者 慕用6222994 #2
    老师,我设置的是subItem呢,不是subItems。你怎么测试通过的?设置的属性也是date-item呢
    2020-06-19 21:06:49
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师