When the mouse passes through tr, the current background color of tr is changed.
This article mainly introduces the sample code for changing the current background color of tr when the mouse passes through tr. If you need some help, please refer to it.
Example:
The Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = GBK">
<Title> change the color of tr after the mouse </title>
</Head>
<Body>
<Table align = "center" width = "100%" border = "1" cellspacing = "1" cellpadding = "1">
<Tr style = "cursor: hand" onmousemove = "changeTrColor (this)">
<Td align = "center"> 1 </td>
<Td height = "20"> 123 </td>
<Td height = "20"> abvx </td>
<Td height = "20"> 465465 </td>
<Td height = "20"> 546654654 </td>
</Tr>
<Tr style = "cursor: hand" onmousemove = "changeTrColor (this)">
<Td align = "center"> 1 </td>
<Td height = "20"> 123 </td>
<Td height = "20"> abvx </td>
<Td height = "20"> 465465 </td>
<Td height = "20"> 546654654 </td>
</Tr>
<Tr style = "cursor: hand" onmousemove = "changeTrColor (this)">
<Td align = "center"> 1 </td>
<Td height = "20"> 123 </td>
<Td height = "20"> abvx </td>
<Td height = "20"> 465465 </td>
<Td height = "20"> 546654654 </td>
</Tr>
</Table>
<Script type = "text/javascript">
Function changeTrColor (obj ){
Var _ table = obj. parentNode;
For (var I = 0; I <_ table. rows. length; I ++ ){
_ Table. rows [I]. style. backgroundColor = "";
}
Obj. style. backgroundColor = "blue ";
}
</Script>
</Form>
</Body>
</Html>