猿问

请看下这段代码的问题

问题可能很低端。。

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

         

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

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

        function changeColor(trs[i]){

            trs[i].onmouseover = function(){

                trs[i].style.backgroundColor = 'grey';

            }

            trs[i].onmouseout = function(){

                trs[i].style.backgroundColor = 'white';

            }

        }

    }

MMTTMM
浏览 423回答 1
1回答

慕田峪7331174

其实只是你写错了代码而已:var trs = document.getElementsByTagName("tr");for(var i = 0;i < trs.length;i++){&nbsp; &nbsp; (function changeColor(tr){&nbsp; &nbsp; &nbsp; &nbsp; tr.onmouseover = function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tr.style.backgroundColor = 'grey';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; tr.onmouseout = function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tr.style.backgroundColor = 'white';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; })(trs[i]);}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答