我有对象,我想打印他们的名字和属性名称。我怎样才能做到这一点。我可以访问他们的属性值。就像我想要打印对象名称(例如“第一”和“第二”)以及它们的属性(例如“值”和“文本”)不想打印值
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function (){
var myDate= {
'first':{value:'30',text:'i am the one'},
'second':{value:'50',text:'i am the second'}
}
$('a').click(function (){
var t= $(this).text();
if(t=="both"){
$('.text').text(myDate['first'] + '' + myDate['second'] );
} else {
$('.text').text(myDate[t]);
}
});
});
</script>
</head>
<body>
<div class="text"></div>
<a href="#">first</a> <a href="#">second</a>
<a href="#">both</a>
</body>