遍历属性值

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JSON 对象</h1>
  6.  
  7. <p>使用括号表示法访问属性值。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var myObj, x;
  13. myObj = {"name":"Bill Gates", "age":62, "car":null};
  14. for (x in myObj) {
  15. document.getElementById("demo").innerHTML += myObj[x] + "<br>";
  16. }
  17. </script>
  18.  
  19. </body>
  20. </html>