如何将json 数据显示在表格里面?

例如:vardatanav=[{"name":"张三","position":"1","powerrate":"2","waterrate":"3","healthcos... 例如:
var datanav = [{ "name": "张三", "position": "1", "powerrate": "2", "waterrate": "3", "healthcosts": "4", "watermeter": "5", "ammeter": "6", "linkman": "7", "phone": "8", "rental": "9", "tenancy": "10", "remark": "11" }, { "name": "李四", "position": "11", "powerrate": "10", "waterrate": "9", "healthcosts": "8", "watermeter": "7", "ammeter": "6", "linkman": "5", "phone": "4", "rental": "3", "tenancy": "2", "remark": "1"}];

显示在表格里面 用js 循环
展开
 我来答
yugi111
推荐于2017-09-12 · TA获得超过8.1万个赞
知道大有可为答主
回答量:5.1万
采纳率:70%
帮助的人:1.3亿
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>MODEL PAGE</title>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}

td,th {
border: 1px solid black;
}
</style>
<script type="text/javascript" src="jquery-1.8.0.min.js"></script>
<script type="text/javascript">
var datanav = [
{
"name" : "张三",
"position" : "1",
"powerrate" : "2",
"waterrate" : "3",
"healthcosts" : "4",
"watermeter" : "5",
"ammeter" : "6",
"linkman" : "7",
"phone" : "8",
"rental" : "9",
"tenancy" : "10",
"remark" : "11"
},
{
"name" : "李四",
"position" : "11",
"powerrate" : "10",
"waterrate" : "9",
"healthcosts" : "8",
"watermeter" : "7",
"ammeter" : "6",
"linkman" : "5",
"phone" : "4",
"rental" : "3",
"tenancy" : "2",
"remark" : "1"
}
];
window.onload = function ()
{
var table = document.getElementsByTagName ('table')[0];
for ( var i = 0; i < datanav.length; i++)
{
var tr = table.insertRow (table.rows.length);
var obj = datanav[i];
for ( var p in obj)
{
if (p == 'tenancy')
{
break;
}
var td = tr.insertCell (tr.cells.length);
td.innerText = obj[p];
}
}
}
</script>
</head>
<body>
<table>
<tr>
<th>租户</th>
<th>水费</th>
<th>电费</th>
<th>卫生费</th>
<th>水表位置</th>
<th>电表位置</th>
<th>联系人</th>
<th>电话</th>
<th>房费</th>
<th>租赁合同期限</th>
</tr>
</table>
</body>
</html>
更多追问追答
追问
不引用  src="jquery-1.8.0.min.js   怎么做  用最简单的循环方法
追答
我就是放那里,我没有用啊,放都不行么?
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式