编辑下面的代码:【加编码】
<html> <body> <p>点击按钮循环对象属性。</p> <button onclick="myFunction()">点我</button> <p id="demo"></p> <script> function myFunction() { var person = {fname:"John", lname:"Doe", age:25}; var text = ""; var x; for (x in person) { text += person[x] + " "; } document.getElementById("demo").innerHTML = text; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂