<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
<p>
有两种方式可以访问对象属性:
</p>
<p>
你可以使用 .property 或 ["property"].
</p>
<p id="demo"></p>
<script>
var person = {
firstName : "John",
lastName : "Doe",
id : 5566
};
document.getElementById("demo").innerHTML =
person["firstName"] + " " + person.lastName;
</script>
</body>
</html>
27
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>菜鸟教程(runoob.com)</title>
6
</head>
7
<body>
8
9
<p>
10
有两种方式可以访问对象属性:
11
</p>
12
<p>
13
你可以使用 .property 或 ["property"].
14
</p>
15
<p id="demo"></p>
16
<script>
17
var person = {
18
firstName : "John",
19
lastName : "Doe",
20
id : 5566
21
};
22
document.getElementById("demo").innerHTML =
23
person["firstName"] + " " + person.lastName;
24
</script>
25
26
</body>
27
</html>