JavaScript的对象属性的反射
取得某个Javascript对象的所有属性与属性值
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 脚本测试 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
// 1.创建一个空对象:var o =new object();
// 2.创建对象直接量:
// var cricle={x:0,y:0,radius:2}
// var homer={
// name:"Homer Simpson",
// age:34,
// married:true,
// email:"zzy@163.com"
// }
// 3属性的设置和查询
// var book=new object();
// book.title="测试";
var homer = {
name : "Homer Simpson",
age : 34,
married : true,
email : "zzy@163.com",
ss : function() {
}
}
function Test() {
homer.title = "title test";
displayppName(homer);
}
function displayppName(obj) {
var name = "";
for (var name1 in obj)
name += name1.toUpperCase() + ":" + obj[name1] + "\n";
alert(name);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="button" name="btnTest" onclick="Test();" value="测试">
</BODY>
</HTML>