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