改变背景色时为什么一定要调用函数,不能直接使用对象改变呢?

来源:9-22 编程练习

tzstone

2015-04-05 08:40

程序如下:

window.onload = function(){                 

     // 鼠标移动改变背景,可以通过给每行绑定鼠标移上事件和鼠标移除事件来改变所在行背景色。

        var mytr=document.getElementsByTagName("tr"); 

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

            mytr[i].onmouseover=function(){

myte[i].style.backgroundColor="#f2f2f2";}

mytr[i].onmouseout=function(){

myte[i].style.backgroundColor="#fff";}

            }  

}


写回答 关注

2回答

  • 慕莱坞5242466
    2022-04-10 10:08:17

    应该是attime=time.getHours()+quot;:quot;+time.getMinutes()+quot;:quot;+time.getSeconds();,在第一个:后少了个+

    fitrrykgpbvrpsiagiaysajbzhdqrzhrjedjaegaydazahnaqbk

  • 康振宁
    2015-04-07 11:22:49

     var tbody = document.getElementById('table').lastChild;    

                    trs = tbody.getElementsByTagName('tr');   

                    for(var i =1;i<trs.length;i++){

                        trs[i].onmouseover = function(){

                            this.style.backgroundColor ="#f2f2f2";

                        } 

                        trs[i].onmouseout = function(){

                            this.style.backgroundColor ="#fff";

                        } 

                    }  


    用户1115...

    为什么?

    2015-04-29 22:53:57

    共 1 条回复 >

JavaScript进阶篇

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

467403 学习 · 21877 问题

查看课程

相似问题