Home > Web Front-end > JS Tutorial > Example code sharing using JS to implement interlaced color change effect on list pages

Example code sharing using JS to implement interlaced color change effect on list pages

黄舟
Release: 2017-03-25 14:27:02
Original
1605 people have browsed it

This article mainly introduces in detail the JS implementation of the interlaced color change effect on the list page, which has a certain reference value. Interested friends can refer to it

Take a look first Interlaced color change effect:

Example code sharing using JS to implement interlaced color change effect on list pages

Code:

<head runat="server">
 <title></title>
 <script type="text/javascript">
  window.onload = function () {
   var otab = document.getElementById(&#39;tab1&#39;);
   var thiscolor = &#39;&#39;;
   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 = &#39;#00FFFF&#39;;
    };
    otab.tBodies[0].rows[i].onmouseout = function () {
     this.style.background = thiscolor;
    };
    if (i % 2) {
     otab.tBodies[0].rows[i].style.background = &#39;&#39;;
    }
    else {
     otab.tBodies[0].rows[i].style.background = &#39;#FFFF00&#39;;
    }
   }
  };
 </script>
</head>
<body>
 <table id="tab1" border="1" style="text-align: center; width: 500px; margin: 200px auto">
  <thead>
   <tr style="background-color: #FF0000">
    <td>
     种族名称
    </td>
    <td>
     种族简称
    </td>
    <td>
     英雄
    </td>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td>
     人类联盟
    </td>
    <td>
     HUM
    </td>
    <td>
     代表性英雄:AM
    </td>
   </tr>
   <tr>
    <td>
     兽人部落
    </td>
    <td>
     ORC
    </td>
    <td>
     代表性英雄:BM
    </td>
   </tr>
   <tr>
    <td>
     不死亡灵
    </td>
    <td>
     UD
    </td>
    <td>
     代表性英雄:DK
    </td>
   </tr>
   <tr>
    <td>
     暗夜精灵
    </td>
    <td>
     NE
    </td>
    <td>
     代表性英雄:DH
    </td>
   </tr>
  </tbody>
 </table>
</body>
Copy after login

The above is the detailed content of Example code sharing using JS to implement interlaced color change effect on list pages. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template