JavaScript语法详解
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript语法详解相关的知识,希望对你有一定的参考价值。
一、JavaScript循环语句
1.for循环、for/in
<!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>
<!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
<!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>
<!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>
以上是关于JavaScript语法详解的主要内容,如果未能解决你的问题,请参考以下文章