标签:body src doctype window 数组 idt write bsp 二维数组
补觉中...
1.不一样的乘法表:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>倒立的乘法表</title> </head> <body> <script type="text/javascript"> var k = 9; var str = ""; str += "<table width=‘600‘ border=‘1‘ rules=‘all‘ align=‘center‘>"; for(var k = 9; k>0; k--) { for(var i = k; i>0; i--) { str += "<tr>"; for(var j = 9; j>0; j--) { str += "<td>"+j+‘*‘+i+‘=‘+(j*i)+"</td>"; if(i>1) { i--; }else { break; } } str += "</tr>"; } } str += "</table>"; document.write(str); </script> </body> </html>
效果图:
2.数字图案:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>数字图形</title> </head> <body> <script type="text/javascript"> var a = window.prompt("请输入10以内的一个数"); for(var i=a; i>0; i--) { for(var j=i; j>0; j--) { document.write(i); } document.write("<br>"); } for(var m=2; m<=a; m++) { for(var n=1; n<=m; n++) { document.write(m); } document.write("<br>"); } </script> </body> </html>
效果图:
3.二位数组中的平均值和最大值:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>二维数组</title> </head> <body> <script type="text/javascript"> var arr = [ [1,2,3,4], [5,6,7,8], [9,10,11,12] ] var a = 0; var max = arr[0][0]; for(var i=0; i<arr.length; i++) { for(var j = 0, length2 = arr[i].length; j < length2; j++){ a += arr[i][j]; if(max<arr[i][j]){ max = arr[i][j]; } } } document.write(a/(arr.length*length2)+"是平均值.<br>"); document.write(max+"是最大值<br>"); </script> </body> </html>
标签:body src doctype window 数组 idt write bsp 二维数组
原文地址:http://www.cnblogs.com/panbee/p/6135990.html