Only one line of code:
<Tr style = "<% # (Container. DisplayIndex % 2 = 0 )? "Background-color: white;": "background-color: # EEEEEE;" %> ">
In addition, js is directly used to process the alternate colors of all tr values on the entire page:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> webpage special effect tutorial | Linkweb.cn/Js | --- Select All and change the TR color </title>
<Mce: script language = "JavaScript" type = "text/javascript tutorial" for = "checkbox" event = "onclick"> <! --
Tr_bgcolor (this );
// --> </Mce: script>
<Mce: script language = "JavaScript" type = "text/javascript"> <! --
Function tr_bgcolor (c ){
Var tr = c. parentNode. parentNode;
Tr. rowIndex % 2 = 0? Tr. style. backgroundColor = c. checked? '# Add6a6': '# eee': tr. style. backgroundColor = c. checked? '# Add6d6 ':'';
}
Function selall (obj ){
For (var I = 0; I <obj. form. elements. length; I ++)
If (obj. form. elements [I]. type = 'checkbox' & obj. form. elements [I]! = Obj ){
Obj. form. elements [I]. checked = obj. checked;
Tr_bgcolor (obj. form. elements [I]);
}
}
// --> </Mce: script>
</Head>
<Body>
<Form id = "form1" name = "form1" method = "post" action = "">
<Table width = "500" border = "0" align = "center" cellpadding = "0" cellspacing = "1" bgcolor = "#888888">
<Tr> <td> <input name = "selectall" type = "checkbox" value = "select all" onclick = "selall (this) "/> </td> </tr>
<Tr> <td>
<Table width = "100%" border = "0" cellpadding = "0" cellspacing = "0" bgcolor = "# FFFFFF">
<Tr style = "background-color: # eee;" mce_style = "background-color: # eee; "> <td width =" 6% "> <input type =" checkbox "name =" checkbox "/> </td> <td width =" 94% "> **** * ****************** </td> </tr>
<Tr> <td> <input type = "checkbox" name = "checkbox"/> </td> <td> ************* * ********* </td> </tr>
<Tr style = "background-color: # eee" mce_style = "background-color: # eee "> <td> <input type =" checkbox "name =" checkbox "/> </td> <td> ************ * ********** </td> </tr>
<Tr> <td> <input type = "checkbox" name = "checkbox"/> </td> <td> ************* * ********* </td> </tr>
<Tr style = "background-color: # eee" mce_style = "background-color: # eee "> <td> <input type =" checkbox "name =" checkbox "/> </td> <td> ************ * ********** </td> </tr>
<Tr> <td> <input type = "checkbox" name = "checkbox"/> </td> <td> ************* * ********* </td> </tr>
<Tr style = "background-color: # eee" mce_style = "background-color: # eee "> <td> <input type =" checkbox "name =" checkbox "/> </td> <td> ************ * ********** </td> </tr>
<Tr> <td> <input type = "checkbox" name = "checkbox"/> </td> <td> ************* * ********* </td> </tr>
<Tr style = "background-color: # eee" mce_style = "background-color: # eee "> <td> <input type =" checkbox "name =" checkbox "/> </td> <td> ************ * ********** </td> </tr>
</Table>
</Td> </tr>
</Table>
</Form>
</Body>
</Html>
Or
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> tr colors of table rows alternate </title>
<Mce: style> <! --
# AB {border-collaps tutorial e: collapse; width: 800px; margin: 10px auto ;}
# AB td {border: 1px solid # ccc; border-top: none; padding: 4px; text-align: center ;}
. Tr1 {background-color: # eee; color: red ;}
. Tr2 {background-color: # ccc; color: blue ;}
--> </Mce: style> <style mce_bogus = "1"> # AB {border-collapse: collapse; width: 800px; margin: 10px auto ;}
# AB td {border: 1px solid # ccc; border-top: none; padding: 4px; text-align: center ;}
. Tr1 {background-color: # eee; color: red ;}
. Tr2 {background-color: # ccc; color: blue ;}</style>
<Mce: script type = "text/javascript"> <! --
Function colortd (ob ){
Obob = ob. rows;
For (var I = 0; I <ob. length; I ++ ){
If (I % 2) ob (I). className = "tr1 ";
Else ob (I). className = "tr2 ";
}
}
// --> </Mce: script>
</Head>
<Body onload = "colortd (AB)">
<Table id = "AB">
<Tr> <td> hang ------------ 1 </td> </tr>
<Tr> <td> hang ------------ 2 </td> </tr>
<Tr> <td> hang ------------ 3 </td> </tr>
<Tr> <td> hang ------------ 4 </td> </tr>
</Table>
</Body>
</Html>