1)
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6 <title>New Web Project</title> 7 <script type="text/javascript"> 8 function fun() 9 {//利用for...in的循环机制来遍历对象的所有属性 10 var obj=new Object(); 11 obj.title="javascript"; 12 obj.author="自在飞花轻似梦"; 13 obj.sex="男"; 14 for(prop in obj) 15 {//一次输出 obj对象的每一个属性 16 console.log("obj."+prop+"="+obj[prop]); 17 } 18 } 19 fun(); 20 </script> 21 </head> 22 <body> 23 <h1>New Web Project Page</h1> 24 </body> 25 </html>
输出:
时间: 2024-10-01 07:09:49