循环遍历对象 遍历啥意思

<!DOCTYPE html>
<html>
<body>
<p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
<button onclick="myFunction()">点击这里</button>
<p id="demo"></p>

<script>
function myFunction()
{
var x;
var txt="";
var person={fname:"Bill",lname:"Gates",age:56};

for (x in person) // 大侠这句是不是说x变成了person的属性啦?

{
txt= txt+person[x];
}

document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
</html>
看不懂 怎么for循环起来 变量txt 就txt= txt+person[x];样接管了 对象person所有属性的值了.
恳请大侠给小弟上上课呗,俺高中文化自学这个太费劲了.现在扔了海尔工厂工作专心学习它. 谢谢师傅了
{
txt= txt+person[x];
}

document.getElementById("demo").innerHTML=txt;
}

把还有这个不懂 把上面txt= txt+person[x]; 改成 txt=person[x]
输入结果竟然是person的最后一个属性age的值 56 咋回事 ???

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网