创建 person 对象(单行)

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 对象创建</h1>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. // 创建对象:
  11. var person = {firstName:"Bill", lastName:"Gates", age:62, eyeColor:"blue"};
  12.  
  13. // 显示对象中的数据:
  14. document.getElementById("demo").innerHTML =
  15. person.firstName + " 已经 " + person.age + " 岁了。";
  16. </script>
  17.  
  18. </body>
  19. </html>