json
let users = [
{
"name": "Bill",
"sex": "1",
"phone": "1377777777"
},
{
"name": "Biaall",
"sex": "1",
"phone": "13464537564"
},
{
"name": "Billgdsaf",
"sex": "2",
"phone": "13772345235"
}
];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table>
<caption>table</caption>
<tr>
<th>name</th>
<th>sex</th>
<th>phone</th>
</tr>
<tr>
<td><div class="name"></div></td>
<td><div class="sex"></div></td>
<td><div class="phone"></div></td>
</tr>
<tr>
<td><div class="name"></div></td>
<td><div class="sex"></div></td>
<td><div class="phone"></div></td>
</tr>
<tr>
<td><div class="name"></div></td>
<td><div class="sex"></div></td>
<td><div class="phone"></div></td>
</tr>
</table>
<script>
let users = [
{
"name": "Bill",
"sex": "1",
"phone": "1377777777"
},
{
"name": "Biaall",
"sex": "1",
"phone": "13464537564"
},
{
"name": "Billgdsaf",
"sex": "2",
"phone": "13772345235"
}
];
let names = document.getElementsByClassName("name");
let sexs = document.getElementsByClassName("sex");
let phones = document.getElementsByClassName("phone");
for (let i = 0; i < 3; i++) {
names[i].innerText = users[i].name;
sexs[i].innerText = users[i].sex;
phones[i].innerText = users[i].phone;
}
</script>
</body>
</html>
|