Effect: A color interlaced, the mouse moved up, the row is selected to change color, followed by the mouse away from its area, the color changed back to the original color.
First, table interlaced between the style-html code
First, we need to have a form.
1 <TableID= ' Tab1 'Border=1, Align= ' Center ',, Solid>2 <thead>3 <TD>Number</TD><TD>Name</TD><TD>Age</TD>4 <thead>5 <tbody>6 <TR><TD>001</TD><TD>Generals</TD><TD>24</TD></TR>7 <TR><TD>002</TD><TD>Bell Goddess</TD><TD>20</TD></TR>8 <TR><TD>003</TD><TD>Fang, big guy.</TD><TD>23</TD></TR>9 <TR><TD>004</TD><TD>Master Weng</TD><TD>23</TD></TR>Ten </tbody> One </Table>
Second, add JS code
Execute code after window.onload loads the window
<script>window.onload=function(){ varOtab = document.getElementById (' tab1 ')); Gets the table table element saved in the
OtabvarOLDCOLR = ' '; Save the color of the original rows for(vari=0;i<otab.tbodies[0].rows.length;i++{//for Loops how many lines rows represent rows, Tbodies represents the first table tbody otab.tbodies[0].rows[i].onmouseover =function() {//Add move event OLDCOLR= This. Style.background; Assign your original color to an empty string This. Style.background = ' green '; Move into green} otab.tbodies[0].rows[i].onmouseout =function() {//Add move-out event This. Style.background =OLDCOLR; Assign a previous saved old color to yourself}if(i%2) {otab.tbodies[0].rows[i].style.background = ' #CCC '; }Else{otab.tbodies[0].rows[i].style.background = ' Red '; } } };</script>
Third, the effect
Put the mouse on the first line, the first line turns green
Mouse away, then change back to the original color
Dom text App-table interlaced style