实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JS打印一个三角形</title> </head> <body> <script type="text/javascript"> var i="0"; var x="*"; while(i<30){ var h=1; while(h<=i){ document.write(x) h++ } document.write('<br>') i++ document.write('<center>') } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jS乘法口诀</title> </head> <body> <script type="text/javascript"> for (var i = 1; i <= 9; i++) { for (var j =i; j<= 9; j++) { var kong=" " if (i*j<10) { kong+=" " } document.write(i+'x'+j+'='+(i*j)+kong) } document.write('<br>') } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jS乘法口诀</title> </head> <body> <script type="text/javascript"> for (var i = 1; i <= 9; i++) { for (var j =1; j<=i; j++) { var kong=" " if (i*j<10) { kong+=" " } document.write(i+'x'+j+'='+(i*j)+kong) } document.write('<br>') } </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>打印三角形</title> </head> <body> <script type="text/javascript"> var i=1; var x="*"; while(i<=30){ var j=1; //j=1是初始化变量这里是每循环一次输出*号再换个行每次循环星号的个数加一 while(j<=i){ document.write(x); j++ //就是只要while(j<=i)条件成立那么就会执行并输出document.write(x)+1 } document.write("<br>"); i++ //外层的循环市为了输出换行,里面的循环市为了输出星号 } </script> <!-- 关于双while循环的理解:当i<=30的时候执行第二个循环j,当j小于等于i的时候执行输出“*”那这里的*为什么会每一次会增加1呢?为什么不是不直接x++? --> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例