<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<button onclick="ddd(this.name)" name="people">11111111111111111</button>
<script type="text/javascript" src="js/jquery.js"></script>
<script>
var aa;
function getData() {
$.ajax({
type: "get",
url: "test.json",
dataType: "json",
async: false,
success: function(data) {
aa = data;
}
});
return aa;
}
var b = getData();
console.log(b)
function ddd(obj) {
$.each(b, function(k, v) {
if(k == obj) {
for(var i in v){
console.log(v[i].name)
}
}
});
}
</script>
</body>
</html>
test.json:
{
"people":[
{"name":"张三",
"age":"3"},
{"name":"里斯",
"age":"4"}
],
"employees": [
{ "firstName":"Bill" , "lastName":"Gates" },
{ "firstName":"George" , "lastName":"Bush" },
{ "firstName":"Thomas" , "lastName":"Carter" }
]
}
网友评论