JavaScript selection set

<! DOCTYPE HTML > 
< HTML lang = "EN" > 
< head > 
    < Meta charset = "UTF-. 8" > 
    < title > selections </ title > 
    < Script > 
        
        the window.onload =  function () { 

            // of aList = document.getElementsByTagName ( 'List1'); 
            // used herein TagName Looking element, without the use of the id, do not use the class name, the tag name only need to enter the table. 

            of aList = document.getElementsByTagName ( ' Li ' );
            aList02 = Document.getElementById ( ' list02 ' ) 
            aLi02 = aList02.getElementsByTagName ( ' Li ' ); 

            // this method is used to read the html all like labels, the labels used for certain types of time necessary to provide a superset of the id element , to get the parent byId set, then set within parent byTab 

            var ILEN = aList.length; 

            // Alert (of aList); 
            // Alert (aList.length); TagName acquired directly through the element, the array is not, nor is the element , but the selection set !! !!. 

            of aList [ . 4 ] .style.backgroundColor =  ' Red ' ; 

            // selection set by only using the index can not be simultaneously a plurality of, so you want to set all the need for loop. 

            for (I = 0;i<ilen;i++){

                aList[i].style.backgroundColor = 'cyan';

                if(0==i%2){
                    aList[i].style.backgroundColor = 'red';    
                }
            }

            var iLen02=aLi02.length;
            alert(iLen02);

            for(i=0;i<iLen02;i++){

                aLi02[i].style.backgroundColor = 'plum';
                if(0==i%2){
                    aLi02[i].style.backgroundColor = 'violet';
                }

            }

        }


    </script>
</head>
<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
    </ul>
    <ul id="list02">
        <li>11</li>
        <li></12li>
        <li>13</li>
        <li>14</li>
        <li>15</li>
        <li>16</li>
        <li>17</li>
        <li>18</li>
    </ul>
</body>
</html>

 

Guess you like

Origin www.cnblogs.com/jrri/p/11347327.html