为什么鼠标滑过颜色这么写不对啊,划过的时候整个表格都变色了

来源:9-22 编程练习

qq_0投币许愿_04192931

2018-09-28 11:07


//鼠标滑过的背景颜色
     function onload2(){
        var table=document.getElementById("table");
        var trs=table.childNodes;
          for(var i=0;i<trs.length;i++)
          {
              trs[i].onmouseover=function()
              {
                  //alert(trs.length);
                  this.style.backgroundColor="#f2f2f2";
              }
              trs[i].onmouseout=function()
              {
                  this.style.backgroundColor="";
              }
          }
    }

写回答 关注

1回答

  • 京兆
    2018-09-28 13:25:26

    var trs=table.childNodes;  这一句换成 var trs = table.getElementsByTagName("tr");   我给不你了你完美的解释! 

JavaScript进阶篇

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

467393 学习 · 21877 问题

查看课程

相似问题