JS small function of of list page interlaced color simple implementation

  • 2020-03-30 00:02:23
  • OfStack

Effect:

< img border = 0 SRC = "/ / files.jb51.net/file_images/article/201311/20131128145923768.gif" >

Code:


<head runat="server">
    <title></title>
    <script type="text/javascript">
        window.onload = function () {
            var otab = document.getElementById('tab1');
            var thiscolor = '';
            for (var i = 0; i < otab.tBodies[0].rows.length; i++) {
                otab.tBodies[0].rows[i].onmouseover = function () {
                    thiscolor = this.style.background;
                    this.style.background = '#00FFFF';
                };
                otab.tBodies[0].rows[i].onmouseout = function () {
                    this.style.background = thiscolor;
                };
                if (i % 2) {
                    otab.tBodies[0].rows[i].style.background = '';
                }
                else {
                    otab.tBodies[0].rows[i].style.background = '#FFFF00';
                }
            }
        };
    </script>
</head>
<body>
    <table id="tab1" border="1" style="text-align: center; width: 500px; margin: 200px auto">
        <thead>
            <tr style="background-color: #FF0000">
                <td>
                     Ethnic name 
                </td>
                <td>
                     RACES referred to as" 
                </td>
                <td>
                     hero 
                </td>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                     Human alliance 
                </td>
                <td>
                    HUM
                </td>
                <td>
                     Representative heroes: AM
                </td>
            </tr>
            <tr>
                <td>
                     The orc tribes 
                </td>
                <td>
                    ORC
                </td>
                <td>
                     Representative heroes: BM
                </td>
            </tr>
            <tr>
                <td>
                     undead 
                </td>
                <td>
                    UD
                </td>
                <td>
                     Representative heroes: DK
                </td>
            </tr>
            <tr>
                <td>
                     The night elves 
                </td>
                <td>
                    NE
                </td>
                <td>
                     Representative heroes: DH
                </td>
            </tr>
        </tbody>
    </table>
</body>


Related articles: