Operator 1-js Learning Note 2015-6-13 (56th day)

Source: Internet
Author: User

Application of the model in the actual case:

Alternating colors:

<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Script>/*var i = 0;i++;if (i = = 5) {i = 0;} i%=5;*/window.onload= function (){    varALi=document.getElementsByTagName ('Li'); vararr= [ 'Red', 'Yellow', 'Blue' ];  for( varI=0; I<ali.length; I++) {Ali[i].index=i; Ali[i].style.background=Arr[i%Arr.length]; //If this is just ali[i].style.background = Arr[i], then only 3 lines of Li's background for the loop will be finished, after the mold can loop to get 0,1,2, such results, and then continue to add style to Li. Ali[i].onmouseover= function (){             This. Style.background= 'Gray';        }; Ali[i].onmouseout= function (){             This. Style.background=arr[ This. Index%Arr.length];    }; }};</Script><style>Li{Height:24px;Margin-bottom:3px;List-style:None; }</style></Head><Body><ulID= "UL1">    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li>    <Li></Li></ul></Body></HTML>

The use of inverse operators in real-world cases:

<!DOCTYPE HTML><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Untitled Document</title><Script>window.onload= function (){    varAINP=document.getElementsByTagName ('input'); //ainp[1].checked = false;    //ainp[2].checked = true;ainp[0].onclick= function (){         for( varI=1; I<ainp.length; I++) {ainp[i].checked= !ainp[i].checked;///*if (ainp[i].checked) {ainp[i].checked = false;            } else {ainp[i].checked = true; }            */        }    };};</Script></Head><Body><inputtype= "button"value= "Reverse Selection" /><ul>    <Li><inputtype= "checkbox"checked/></Li>    <Li><inputtype= "checkbox" /></Li>    <Li><inputtype= "checkbox"checked/></Li>    <Li><inputtype= "checkbox" /></Li>    <Li><inputtype= "checkbox" /></Li></ul></Body></HTML>

Operator 1-js Learning Note 2015-6-13 (56th day)

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.