首页 > 代码库 > javascript5

javascript5

  • %运算符的使用
技术分享
 1 <!DOCTYPE html> 2 <html> 3     <head> 4         <meta charset="UTF-8"> 5         <title></title> 6         <script type="text/javascript"> 7             window.onload=function(){ 8                 var aLi=document.getElementsByTagName(li); 9                 var arr=[red,yellow,blue];10                 for(var i=0;i<aLi.length;i++){11                     aLi[i].index=i;12                     aLi[i].style.background=arr[i%arr.length];13                     14                     aLi[i].onmouseover=function(){15                         this.style.background=#000;16                     }17                     aLi[i].onmouseout=function(){18                         this.style.background=arr[this.index%arr.length];19                     }20                 }21             }22             /*23              说明:24                  0%3=025                  1%3=126                  2%3=227                  3%3=028                  4%3=129                  5%3=230                  6%3=031                  7%3=132                  8%3=233                  9%3=034              * */35         </script>36     </head>37     <body>38         <ul>39             <li></li>40             <li></li>41             <li></li>42             <li></li>43             <li></li>44             <li></li>45             <li></li>46             <li></li>47             <li></li>48         </ul>49     </body>50 </html>
View Code
技术分享
 1 <!DOCTYPE html> 2 <html> 3     <head> 4         <meta charset="UTF-8"> 5         <title></title> 6         <script type="text/javascript"> 7             window.onload=function(){ 8                 var aLi=document.getElementsByTagName(li); 9                 var arr=[red,yellow,blue];10                 var str=‘‘;11                 for(var i=0;i<aLi.length;i++){12                     aLi[i].index=i;13                     aLi[i].style.background=arr[i%arr.length];14                     15                     aLi[i].onmouseover=function(){16                         str=this.style.background;//移入先存颜色17                         this.style.background=#000;18                     }19                     aLi[i].onmouseout=function(){20                         this.style.background=str;//移出赋值颜色21                     }22                 }23             }24             /*25              说明:26                  0%3=027                  1%3=128                  2%3=229                  3%3=030                  4%3=131                  5%3=232                  6%3=033                  7%3=134                  8%3=235                  9%3=036              * */37         </script>38     </head>39     <body>40         <ul>41             <li></li>42             <li></li>43             <li></li>44             <li></li>45             <li></li>46             <li></li>47             <li></li>48             <li></li>49             <li></li>50         </ul>51     </body>52 </html>
View Code

 

javascript5