<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style> * { margin: 0; padding: 0; } table { margin: 150px auto; width: 500px; border: 1px solid #000; } tr { height: 40px; } td { border: 1px solid #000; line-height: 40px; text-align: center; } </style> <script> window.onload = function () { var tbody = document.getElementsByTagName("tbody")[0]; var trArr = tbody.getElementsByTagName("tr"); for(var i=0;i<trArr.length;i++){ if(i%2===0){ trArr[i].style.backgroundColor = "#BEBEBE"; }else{ trArr[i].style.backgroundColor = "#D0B8AD" } var color = ""; trArr[i].onmouseover = function () { color = this.style.backgroundColor; this.style.backgroundColor = "#76B481"; } trArr[i].onmouseout = function () { this.style.backgroundColor = color; } } } </script></head><body> <table> <caption>表格一:XXXXXXXX</caption> <thead> <tr> <td>编号</td> <td>姓名</td> <td>年龄</td> </tr> </thead> <tbody> <tr> <td>111</td> <td>姓名</td> <td>13</td> </tr> <tr> <td>222</td> <td>姓名</td> <td>35</td> </tr> <tr> <td>333</td> <td>姓名</td> <td>346</td> </tr> <tr> <td>444</td> <td>姓名</td> <td>23</td> </tr> <tr> <td>555</td> <td>姓名</td> <td>23</td> </tr> <tr> <td>666</td> <td>姓名</td> <td>12</td> </tr> <tr> <td>777</td> <td>姓名</td> <td>32</td> </tr> <tr> <td>888</td> <td>姓名</td> <td>23</td> </tr> <tr> <td>999</td> <td>姓名</td> <td>14</td> </tr> </tbody> </table></body></html>
时间: 2024-10-12 11:09:21