json:建立一個物件,其它一個屬性是陣列;建立一個物件,使用function作為屬性值
阿新 • • 發佈:2019-01-28
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>建立一個物件,其它一個屬性是陣列</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <script type="text/javascript"> var p = { id:1, name:'哈哈', home:['湘潭','長沙','廣州'] }; for(var i=0;i<p.home.length;i++){ document.write(p.home[i]+" "); } </script> </body> </html>
json.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>建立一個物件,使用function做為屬性值</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <script type="text/javascript"> var p = { id:1, name:'哈哈', isLove:true, home:['廣州','深圳'], show : function(str){ alert("你是" + str); } }; //document.write(p.isLove?"已婚":"單身"+"<br/>"); p.show("趙君"); </script> </body> </html>