1. Ladder
:
<style> div{width:30px; height:30px; border:1px solid royalblue; background:red; position:absolute;top:0px ; Left:0px;color: #fff} </style> <script> window.onload=function () { var str = '; for (Var i=0;i<11;i++) { str+= "<div>" +i+ "</div>"; } Document.body.innerhtml=str; var divs=document.getelementsbytagname ("div"); Len=divs.length; for (Var i=0;i<len;i++) { divs[i].style.left+=i*50+10+ "px";//div around 10px pixels divs[i].style.top+=i*50 +10+ "px";//each div is spaced 10px pixels above and below } </script>
2.V character is an algorithm, when the number in half +1, the number increases, more than half of the time the number increases the value is less 6->130 7->100 8->70 ...
<script>window.onload=function(){ varstr = "; for(vari=0;i<11;i++) {str+ = "<div>" +i+ "</div>"; } Document.body.innerHTML=str; varDivs=document.getelementsbytagname ("div"); Len=divs.length; varDown=len%2==0?len/2:math.ceil (LEN/2); varcount=2; for(vari=0;i<len;i++){ if(i<Down ) {Divs[i].style.left+=i*30+10+ "px";//div distance to the leftmost 10px spacing divs[i].style.top+=i*30+10+ "px";//div distance from the top of the 10px spacingalert (divs[i].style.top); }Else if(I>=down &&i<Len) {Divs[i].style.left+=i*30+10+ "px"; Divs[i].style.top+ = (i-count) *30+10+ "px";//The essence is an algorithm number increases the value but becomes less 6->130 7->100 8->70 ...count+=2; } } } </script>3. Nesting for loop prints all elements
<script> var arr=[ [1,2,3,4,5], ["A", "B", "C", "D", "E", "F"], [6,7,8,false,true], ]; for (Var i=0;i<arr.length;i++) {for (var j=0;j<arr[i].length;j++) { alert (Arr[i][j]) } } </script>
2016-05-29 for loops several applications