Dom text App-table interlaced style

Source: Internet
Author: User

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
Otab
varOLDCOLR = ' '; 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.