<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>动态渲染</title>
<style>
table {
width: 300px;
text-align: center;
}
</style>
</head>
<body>
<table border="1" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>性别</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
var users = [
{id: 1, name: '小A同学', age: 23},
{id: 2, name: '小B同学', age: 21},
{id: 3, name: '小C同学', age: 24},]
var tbody = document.querySelector('tbody')
//1.循环遍历users数组
users.forEach(function (item) {
console.log(item)
//2.每一个对象生成一个tr对象
var tr = document.createElement('tr')
// 3.遍历item
for (var key in item) {
var td = document.createElement('td')
td.innerHTML = item[key]
// 把td插入到tr标签内部
tr.appendChild(td)
tbody.appendChild(tr)
}
})
</script>
</body>
</html>
当前位置:网站首页>【JS】动态渲染页面
【JS】动态渲染页面
2022-07-20 21:20:00 【木子欢儿】
边栏推荐
- Vulnhub靶机-doubletrouble
- 3D coordinate system of 3D conversion, perspective rotation and other basic knowledge
- Section 8 of Chapter II: addition, deletion, modification and query of the list
- 2022/07/20 学习笔记 (day12)String字符串
- C # singleton mode
- 架构实战营模块 7 作业
- 3D转换之三维坐标系,透视旋转等基础知识
- 使用优先队列priority_queue实现对基unordered_map于value值的数值筛选
- 数据仓库和数据中台的关系
- Math. Usage of random()
猜你喜欢
随机推荐
【数字图像处理/双边滤波实验】高分课程实验报告分享
第二章 第四节:替换和切割
死锁
(open shortest path first, OSPF) expansion configuration
【超好懂的比赛题解】2021 年四川省大学生程序设计竞赛
伦敦银实时行情能够给人们带来哪方面的信息
第二章 第十四节:字典的概念
Many people think that the development logic of the metauniverse is consistent with that of the Internet, but I don't think so
为什么软件开发有人选择报价高的?那他们是不是亏了?
Math. Usage of random()
节省30%磁盘空间的同时如何保障数据安全?|DB·洞见
企业需要建立属于自己的小程序及APP需要做什么前期工作?
04 extract the latest data
Analysis of flask source code (I) request entry
Section 11 of Chapter 2: tuples
VSS中上传一个文件夹(包括子文件夹和文件)
LeetCode_前缀和_困难_862.和至少为 K 的最短子数组
深入理解完美哈希
[报错]RuntimeError: expected scalar type Double but found Float(torch)
Moment plug-in - time formatting