jsp页面中,js如何解析json数组
[{"name":"张三","birthday":"1947-05-03"},{"name":"李四","birthday":"1929-01-01"}]上诉的json数...
[
{
"name": "张三",
"birthday": "1947-05-03"
},
{
"name": "李四",
"birthday": "1929-01-01"
}
]
上诉的json数组(后台给的)如何在下面的table中显示?
<table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody></tbody></table> 展开
{
"name": "张三",
"birthday": "1947-05-03"
},
{
"name": "李四",
"birthday": "1929-01-01"
}
]
上诉的json数组(后台给的)如何在下面的table中显示?
<table><thead><tr><th>姓名</th><th>年龄</th></tr></thead><tbody></tbody></table> 展开
1个回答
展开全部
给table个id
var data = [{"name": "张三","birthday": "1947-05-03"},{"name": "李四","birthday": "1929-01-01"}];
var table = document.getElementById("table");
var tbody = table.tBodies.item(0) || table;
for(var i = 0,l=data.length;i<l;i++){
var tr_row = document.createElement("tr");
var td_name = document.createElement("td");
var td_birthday = document.createElement("td");
td_name.innerText = data[i].name;
td_birthday.innerText = data[i].birthday;
tr_row.appendChild(td_name);
tr_row.appendChild(td_birthday);
tbody.appendChild(tr_row);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询