1
<p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
2
<button onclick="myFunction()">点击这里</button>
3
<p id="demo"></p>
4
<script>
5
function myFunction() {
6
var x;
7
var txt = "";
8
var person = {
9
fname: "Bill",
10
lname: "Gates",
11
age: 56
12
};
13
for (x in person) {
14
txt = txt + person[x];
15
}
16
document.getElementById("demo").innerHTML = txt;
17
}
18
</script>