简单教程
提交运行
代码编辑器:
<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>
运行结果: