<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>json文件数据渲染</title>
<script src="plugins/jquery3.3.1.min.js"></script>
<script type="text/javascript" src="plugins/data.json"></script>
<style>
.divcss5 {
width: 400px
}
.divcss5 table {
border-color: #000000;
line-height: 30px;
text-align: center;
}
.divcss5 table thead {
color: #000000;
background-color: #00FFFF;
font-size: 20px;
font-weight: 900;
}
.divcss5 table tbody {
color: #FF0000;
background: #C0FFFF;
font-size: 20px;
font-weight: 200;
}
</style>
</head>
<body>
<div class="divcss5">
<table width="95%" border="1" cellspacing="1" cellpadding="0">
<thead>
<tr>
<td>姓名</td>
<td>性别</td>
<td>身份证</td>
</tr>
</thead>
<tbody id="jsonTip">
</tbody>
</table>
</div>
<script>
// 页面加载完后立刻调用getDate方法
$(function () {
console.log("json文件数据", jsonData);
getShow(jsonData);
})
function getShow(data) {
var $jsontip = $("#jsonTip");
// 定义一个变量存储要显示的数据
var s = "";
// 清空数据
$jsontip.empty();
// 遍历拿到的数据(此处采用each方法,也可以采用for循环)
$.each(data.rows, function (index, info) {
s = "<tr><td>" + info.Name + "</td><td>" + info.Sex + "</td><td>" +
info.CardId + "</td><tr>";
// 将要展示的数据追加到页面
$jsontip.append(s);
})
}
</script>
</body>
没有合适的资源?快使用搜索试试~ 我知道了~
读取本地json文件并绘制表格

共3个文件
json:1个
js:1个
html:1个

需积分: 5 4 下载量 120 浏览量
2023-09-30
18:09:10
上传
评论
收藏 31KB ZIP 举报
温馨提示
本文为避免跨域问题,使用了改造过的本地json文件的方法实现读取json数据并绘制表格。 如果发起http请求获取本地 json文件中数据,需要架设本地服务器,本文不做阐述。 具体见:https://sunriver2000.blog.csdn.net/article/details/133437695
资源推荐
资源详情
资源评论
























收起资源包目录






共 3 条
- 1
资源评论


sunriver2000
- 粉丝: 202
- 资源: 53
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
