本文共 1149 字,大约阅读时间需要 3 分钟。
一、JavaScript循环语句
1.for循环、for/in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>Title</title> </head> <body> <script> var array = [1,2,3,4,5,6]; for ( var i=0; i<6; i++){ document.write(array[i]+ " " ); } </script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>Title</title> </head> <body> <script> var array = [1,2,3,4,5,6]; var i; for (i in array){ document.write(array[i]+ "<br/>" ); } </script> </body> </html> |
2.while循环、do...while
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>Title</title> </head> <body> <script> var i = 1; while (i<10){ document.write( "i=" +i+ "<br/>" ) i++; } </script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>Title</title> </head> <body> <script> var i = 10; do { document.write( "i=" +i+ "<br/>" ) i++; } while (i<10) </script> </body> </html> |
本文转自yeleven 51CTO博客,原文链接:http://blog.51cto.com/11317783/1791896
转载地址:http://rpgia.baihongyu.com/