为什么此js函数里只能用this才能实现?

function highlightRows() {

    if(!document.getElementsByTagName) return false;

    var tables = document.getElementsByTagName("table");

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

        var rows = tables[i].getElementsByTagName("tr");

        for(var j =0;j<rows.length;j++){

            rows[j].onmouseover=function(){

                //rows[j].style.fontWeight="bold"; //这样无效

                this.style.fontWeight="bold";

            }

            rows[j].onmouseout=function() {

                //rows[j].style.fontWeight="normal"; //这样无效

                this.style.fontWeight="normal";

            }

        }

    }

}

https://img3.mukewang.com/5bac3e530001cf5703470149.jpg

为什么注释的那两行不行,非要用this呢,这里this不是应该就是指代rows[j]么?

炎炎设计
浏览 557回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript