05迴圈結構

白茶花约發表於2024-03-14
 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
 6     <title>Document</title>
 7 
 8     <script>
 9         /*
10             往瀏覽器視窗上列印
11         */
12         document.write("<h1>中國礦業大學<h1>")
13         document.write("<hr>")
14         
15         /*
16             while for foreach
17         */
18         var arr = ["北京","上海","廣州"]
19         document.write("<ul>")
20         /* 直接列印 index ,是陣列中元素對應索引*/
21         for(var index in arr){
22             document.write("<li>"+arr[index]+"</li>")
23         }
24         document.write("</ul>")
25 
26     </script>
27 
28 </head>
29 <body>
30     
31 </body>
32 </html>

相關文章