取得某個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.建立一個Null 物件: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>