Interlaced color-changing development of JavaScript tables

Source: Internet
Author: User
Tags tag name

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

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.