87,907
社区成员
发帖
与我相关
我的任务
分享
<table>
<thead>
<th>id</th>
<th>name</th>
<th>location</th>
<th>operation</th>
<th>code</th>
</thead>
<tbody id="tb">
</tbody>
</table>
<style>
table {
width: 100%;
text-align: center;
}
table tr:nth-of-type(odd) {
background: #fff;
}
table tr:nth-of-type(even) {
background: #ccc;
}
</style>
<script>
// 二维码
let img = "xxx.png";
let el = document.getElementById("tb");
function ajax() {
let data = [
{
id: "11",
name: "test11",
location: "xxx11"
},
{
id: "22",
name: "test22",
location: "xxx22"
},
{
id: "33",
name: "test33",
location: "xxx33"
}
];
data.forEach(item => {
el.innerHTML += `<tr>
<td>${item.id}</td>
<td>${item.name}</td>
<td>${item.location}</td>
<td>
<button onclick="add()">add</button>
<button onclick="edit(${item.id})">edit</button>
<button onclick="del(${item.id})">delete</button>
</td>
<td>
<img src="${img}" />
</td>
</tr>`;
});
}
function add() {
console.log("add");
}
function edit(id) {
console.log("edit "+id);
}
function del(id) {
console.log("delete "+id);
}
ajax()
</script>