<div class="codetitle"> <span><a style="CURSOR: pointer" data="66863" class="copybut" id="copybut66863" onclick="doCopy('code66863')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code66863"> <br><script type="text/javascript"> <BR>var name ; //儲存tr物件的類別名,當滑鼠移開時進行恢復<BR>function trcolor(){ //表格行顏色間隔顯示<BR>var tabNode = document.getElementsByTagName("table")[0]; <BR>var trNodes = tabNode.rows; <BR>for(var x=1;x<trNodes.length;x ){ <BR>if(x%2 == 1) <BR>trNodes[x].className = "one" ; <BR>else <BR>trNodes[x].className = "two" ; <BR>trNodes[x].onmouseover = function(){ //高亮顯示<BR>name = this.className ; <BR>this.className = "over"; <BR>} <BR>trNodes[x].onmouseout = function(){ //tr物件新增onmouseout事件屬性<BR>this.className = name ; <BR> } <BR>} <BR>} <BR>window.onload = trcolor ; <BR></script> <br><br><style type="text/css"> <BR>table{ width:60% ; border:solid 1px #0066FF;} <BR>table td {border:solid 1px #0099ff;} <BR>a{ text-decoration: none;} <BR>.one{background-color: red;} <🎜;} <BR>.two{background-color: blue;} <BR>.over{background-color: yellow;} <BR></style> <br><br> <br> <br> <table> <br><tr> <br><td>姓名</td> <td>年齡</td> <td>地址</td> <br> </tr> <br><tr> <br><td>張三</td> <td>23</td> <td>北京</td> <br> </tr> <br><tr> <br><td>李四 td></td> <td>25</td> <td>上海</td> <br> </tr> <br><tr> <br><td>王五</td> <td>15</td> <td>廣州</td> <br> </tr> <br><tr> <br><td>唐總</td> <td>20</td> <td>長沙</td> <br> </tr> <br> </table> <br> <br> </div>