<html>
<head>
<title>json</title>
<script language="javascript" type="text/javascript">
window.onload = function(){
//遍历数组
$("blsz").onclick = function(){
$("tta").value = "";
//定义数组
var sz = ["吃饭","睡觉","打豆豆"]
//for in遍历(也可以用普通for遍历)
for(ind in sz){
$("tta").value += sz[ind]+" ";
}
}
// 遍历对象
$("bldx").onclick = function(){
//清空
$("tta").value = "";
/*定义对象*/
var obj = {"name":"程咬金","age":"45"};
/*遍历数组*/
for(ind in obj){
$("tta").value += obj[ind]+" ";
}
}
// 遍历数组对象
$("blszdx").onclick = function(){
$("tta").value = "";
/*定义数组对象*/
var szobj = [{"name":"tom","age":"24"},{"name":"marry","age":"19"}];
/*遍历*/
for(ind in szobj){
$("tta").value += szobj[ind].name+"--->"+szobj[ind].age+"\r\n";
}
}
}
function $(uid){
return document.getElementById(uid);
}
</script>
</head>
<body>
<input type="button" value="数组遍历" id="blsz"/>|
<input type="button" value="对象遍历" id="bldx"/>|
<input type="button" value="数组对象遍历" id="blszdx"/><br/>
<div id="divtext"></div>
<textarea id="tta" style="font-size=20px; width:200px; height=100px;"></textarea>
</body>
</html>