Javascript allows you to easily display the color of table row intervals and highlight them.

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var name; // class name that stores the tr object. It is restored when you move the mouse 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 () {// highlighted
Name = this. className;
This. className = "over ";
}
TrNodes [x]. onmouseout = function () {// tr object add onmouseout event attribute
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> Li Si </td> <td> 25 </td> <td> Shanghai </td>
</Tr>
<Tr>
<Td> Wang Wu </td> <td> 15 </td> <td> Guangzhou </td>
</Tr>
<Tr>
<Td> Tang Zong </td> <td> 20 </td> <td> Changsha </td>
</Tr>
</Table>
</Body>

Related Article

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.