zoukankan      html  css  js  c++  java
  • DOM的事件

    dom0:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <table border="1" width="300px">
        <tr onmouseover="t1(0);" onmouseout="t2(0);"><td>1</td><td>2</td><td>3</td></tr>
        <tr onmouseover="t1(1);" onmouseout="t2(1);"><td>1</td><td>2</td><td>3</td></tr>
        <tr onmouseover="t1(2);" onmouseout="t2(2);"><td>1</td><td>2</td><td>3</td></tr>
    </table>
        <script>
            function t1(n) {
                var myTrs = document.getElementsByTagName("tr")[n];
    
                myTrs.style.backgroundColor="red";
    
            }
            function t2(n) {
                var myTrs = document.getElementsByTagName("tr")[n];
                myTrs.style.backgroundColor="";
    
    
    
            }
        </script>
    </body>
    </html>

    dom1:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <table border="1" width="300px">
        <tr onmouseover="t1(0);" onmouseout="t2(0);"><td>1</td><td>2</td><td>3</td></tr>
        <tr onmouseover="t1(1);" onmouseout="t2(1);"><td>1</td><td>2</td><td>3</td></tr>
        <tr onmouseover="t1(2);" onmouseout="t2(2);"><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.style.backgroundColor="red";
                //    谁调用这个函数this就指向谁
    
                };
                myTrs[i].onmouseout = function () {
                    this.style.backgroundColor="";
                //    谁调用这个函数this就指向谁
    
                };
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    【转】SQL时间函数
    C#操作Word完全方法
    出水芙蓉,风华绝代记民国才女林徽因
    梅超风:我就是那个多年以前的女子
    厉胜男
    南海恶神
    挪窝
    吴若权——洛可可动画电影馆
    美的慢箭
    机械公敌(I, Robot) 场景设定
  • 原文地址:https://www.cnblogs.com/anhao-world/p/14309331.html
Copyright © 2011-2022 走看看