Copy the code code as follows:
<script type="text/javascript">
var name; //Storage the class name of the tr object and restore it when the mouse is moved away
function trcolor(){ //Table row color interval display
var tabNode = document.getElementsByTagName("table")[0];
var trNodes = tabNode.rows;
for(var x=1;x<trNodes.length;x++){
if(x%2 == 1)
trNodes[x].className = "one";
else
trNodes[x].className = "two";
trNodes[x].onmouseover = function(){ //Highlight
name = this.className;
this.className = "over";
}
trNodes[x].onmouseout = function(){ //Add onmouseout event attribute to tr object
this.className = name;
}
}
}
window.onload = trcolor;
</script>
<style type="text/css">
table{ width:60%; border:solid 1px #0066FF;}
table td {border:solid 1px #0099ff;}
a{ text-decoration: none;}
.one{background-color: red;}
.two{background-color: blue;}
.over{background-color: yellow;}
</style>
</head>
<body>
<table>
<tr>
<td>Name</td><td>Age</td><td>Address</td>
</tr>
<tr>
<td>Zhang San</td><td>23</td><td>Beijing</td>
</tr>
<tr>
<td>李思</td><td>25</td><td>Shanghai</td>
</tr>
<tr>
<td>王五</td><td>15</td><td>Guangzhou</td>
</tr>
<tr>
<td>Mr. Tang</td><td>20</td><td>Changsha</td>
</tr>
</table>
</body>