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

求教各位大神 写了一个类似日历的东西

求教各位大神 写了一个类似日历的东西

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>日历</title> <style type="text/css"> #table1 {     border:1px solid black;     width:250px;     height:250px; } #table1 td{     border:1px solid black;     text-align: center;     padding:10px;     width:80px;     height:80px; } #div1 {     background:#ccc;     width:200px;     height:420px;     float:left; } </style> <script type="text/javascript">     window.onload=function (){         var oTd=document.getElementsByTagName('td');         var oDiv=document.getElementById('div1');         var arr=[             "111",             "222",             "333",             "444",             "请问weq",             "cewdw",             "wswsws",             "zxczxc",             "wswsws",             "qaqaqa",             "dedede",             "xsce",         ]         for (var i=0;i<oTd.length;i++){             oTd[i].index=i;             oTd[i].onmouseover=function (){             this.style.backgroundColor="black";             this.style.color="white";         }             oTd[i].onmouseout=function  (){             this.style.background="";             this.style.color="";         }             oDiv.innerHTML=arr[this.index];     }     } </script> </head> <body> <table id="table1" > <tr> <td>a</td> <td>b</td> <td>c</td> </tr> <tr> <td>d</td> <td>e</td> <td>f</td> </tr> <tr> <td>g</td> <td>h</td> <td>i</td> </tr> <tr> <td>j</td> <td>k</td> <td>l</td> </tr> <div id="div1"></div> </table> </body> </html>但是为啥鼠标移入之后左边会显示undefined? 求救求救啊困惑好久啦
查看完整描述

4 回答

已采纳
?
joffyzou

TA贡献45条经验 获得超17个赞

你想写什么效果?是不是鼠标放上去,左边的div里面显示你鼠标所在位置的内容?如果是,把

oDiv.innerHTML=arr[this.index]; 移入到 onmouseover  事件里面去。

查看完整回答
1 反对 回复 2017-11-20
?
慕粉3799017

TA贡献2条经验 获得超1个赞

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

            oTd[i].index=i;

            oTd[i].onmouseover=function (){

            this.style.backgroundColor="black";

            this.style.color="white";

            oDiv.innerHTML=arr[this.index];

        }

            oTd[i].onmouseout=function  (){

            this.style.background="";

            this.style.color="";

            oDiv.innerHTML="";

        }

    }

你看一下这是不是你想要的效果

查看完整回答
1 反对 回复 2017-11-21
?
慕沐9665835

TA贡献3条经验 获得超1个赞

arr[this.index]里的this指向的是window对象,window对象上面没有index属性,所以就显示为undefined了,解决办法参考一楼

查看完整回答
1 反对 回复 2017-11-20
?
超级巨浪大切

TA贡献2条经验 获得超0个赞

谢谢大家的帮助!!! 已经顺利解决了! !!!

查看完整回答
反对 回复 2017-11-21
  • 4 回答
  • 0 关注
  • 2377 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信