fengchuanyu 3 minggu lalu
induk
melakukan
47acefb4a6
2 mengubah file dengan 26 tambahan dan 1 penghapusan
  1. 1 1
      2-JavaScript/19_对像.html
  2. 25 0
      2-JavaScript/练习14_对象展示.html

+ 1 - 1
2-JavaScript/19_对像.html

@@ -25,7 +25,7 @@
             }
         }
 
-        // 获取对象属性
+        // 获取对象属性 使用“.”
         var friendName = person.userName;
 
         // 调用方法

+ 25 - 0
2-JavaScript/练习14_对象展示.html

@@ -35,6 +35,31 @@
                 sex:"男"
             },
         ];
+
+        document.write("<ul>");
+        // 第一步遍历数组
+        for(var i = 0;i<userList.length;i++){
+            //输出数组中所有的值
+            // console.log(userList[i])
+            //输出数组每一个对象的性别
+            // console.log(userList[i].sex);
+            // 如果性别为男那么输出姓名
+            // if(userList[i].sex == "男"){
+            //     console.log(userList[i].userName);
+            // }
+
+            // 第二如果为男性则输出到页面中
+            if(userList[i].sex == "男"){
+                document.write("<li>姓名:"+userList[i].userName+"</li>");
+            }
+
+        }
+        document.write("</ul>");
+
+
+
+        // var arr = [1,2,3]
+        // var num = arr[0]
     </script>
 </body>
 </html>