HTML code:
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title>Interlaced color change</title> </Head> <Body> <TableID= "Tab1"Border= "1"width= "$"Align= "Center" > <TRstyle= "Background-color: #999999;"Align= "Center"> <th>Campus ID</th> <th>Campus Area</th> <th>Operation</th> </TR> <TRAlign= "Center"> <TD>1</TD> <TD>Jinan Branch</TD> <TD><ahref="">Modify</a>|<ahref="">Delete</a></TD> </TR> <TRAlign= "Center"> <TD>2</TD> <TD>Kunshan Branch</TD> <TD><ahref="">Modify</a>|<ahref="">Delete</a></TD> </TR> <TRAlign= "Center"> <TD>3</TD> <TD>Chongqing Branch</TD> <TD><ahref="">Modify</a>|<ahref="">Delete</a></TD> </TR> <TRAlign= "Center"> <TD>4</TD> <TD>Inner Mongolia Branch</TD> <TD><ahref="">Modify</a>|<ahref="">Delete</a></TD> </TR> <TRAlign= "Center"> <TD>5</TD> <TD>Dalian Branch</TD> <TD><ahref="">Modify</a>|<ahref="">Delete</a></TD> </TR> </Table> </Body></HTML>
JavaScript code:
<script>//automatic loading succeeds when the page is openedWindow.onload=function(){ //1. Obtain all the TR from the tag name and store it in the ARR array. varArr=document.getelementsbytagname ("tr"); //2. Judge Odd even to add different styles to iterate over an array for(vari=1;i<arr.length;i++){ //if it is an even row if(i%2==0){ //the style background color of an even line is set to = Bright pinkArr[i].style.backgroundcolor= "Lightpink"; }Else{//Otherwise, it's odd. //The style background color of an odd line is set to dark sky blueArr[i].style.backgroundcolor= "Deepskyblue"; } } } </script>
:
Yang School
Source: http://www.cnblogs.com/xiaoxiao5016
Sharing is happy, but also witnessed the personal growth process, the article is mostly work experience summary and usually learn to accumulate, based on their own cognitive deficiencies are unavoidable, also please correct, common progress.
This article is copyrighted by the author, welcome reprint, but without the consent of the author must retain this paragraph statement, and in the article page obvious location, if there is a problem, can mail ([email protected]) Consulting.
Interlaced color-changing development of JavaScript tables