JavaScript for/in循环的用法实例,虽然For、IN大家用着不习惯,不过各有各的优势和个性,用好了一样是优秀的代码。
<html>
<head>
<title>for/in循环</title>
</head>
<body>
<center><h2>测试for/in循环</h2></center>
<hr>
<script language="JavaScript">
// 变量声明
var prop;
var objAddress = new Object();
objAddress.name = "陈会安";
objAddress.age = "33";
objAddress.phone = "02-22222222";
objAddress.email = "hueyan@ms2.hinet.net";
// 循环语句
for (prop in objAddress){
document.write("属性: " + prop + "=" + objAddress[prop] + "<br>");
}
// liehuo.net
</script>
</body>
</html