Encapsulates a simple interlaced color change

Source: Internet
Author: User
Tags tagname

Code Run Effect:

I contact JS time is not long, for the transfer of parameters and packaging function understanding is not thorough, after several exercises a little sentiment, in order to deepen understanding wrote this simple interlaced color change, I hope to have just contact JS friend
helpful, here is the program code:
<! DOCTYPE html>
<Html>
<Headlang="EN">
<Metacharset="UTF-8">
<Title></Title>
<Style>
*{Margin0;Padding0;List-style:None}
li{
Width100%;
Height40Px;
}
div{
Width100%;
Height40Px;
FloatLeft;
}
</Style>
<Script>
functionTurnTagName,Bgcolor1,Bgcolor2){//Define parameters:1.Label Signature2.First background color3.The second color of the background
VarALi=Document.getElementsByTagName(TagName);//Use this parameter
For(VarI=0;I<ALi.Length;I++){
If(I%2==0){//Determine the parity of each line
ALi[I].Style.Background=Bgcolor1;
}Else{
ALi[I].Style.Background=Bgcolor2;
}
}
}
Window.OnLoad= function(){
Turn' Div ',' Red ',' Blue ');//Call the function, passing the first label name;
Turn' Li ',' Yellow ',' Green ');//Pass the second label name;
}
</Script>
</Head>
<Body>
<Ul>
<Li></li> <li ></li >< li></li><li></li><li></li><li></li><li></li> <li></li><li></li><li></li></ul><div></div><div> </div><div></div><div></div><div></div><div></div>< Div></div><div></div><div></div><div></div><div></div ></body>

Encapsulate a simple interlaced color change

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.