<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table border="1" width="300px">
    <tr><td>1</td><td>2</td><td>3</td></tr>
    <tr><td>1</td><td>2</td><td>3</td></tr>
    <tr><td>1</td><td>2</td><td>3</td></tr>
</table>
    <script>
        var myTrs = document.getElementsByTagName('tr');
        var len =myTrs.length;
        for(var i=0;i<len;i++){
            myTrs[i].onmouseover=function () {
//                谁调用的函数this就会指向谁
                this.style.backgroundColor='red'
            }
            myTrs[i].onmouseout=function () {
//                谁调用的函数this就会指向谁
                this.style.backgroundColor=''
            }
        }
    </script>
</body>
</html>

  

相关文章:

  • 2021-11-05
  • 2021-09-21
  • 2021-10-01
  • 2021-07-14
  • 2021-12-02
猜你喜欢
  • 2021-11-17
  • 2022-12-23
  • 2022-03-02
  • 2021-11-08
  • 2022-12-23
  • 2021-11-17
  • 2021-10-20
相关资源
相似解决方案