<!DOCTYPE html
>
<html lang
="en">
<head
>
<meta charset
="UTF-8">
<meta name
="viewport" content
="width=device-width, initial-scale=1.0">
<title
>Document
</title
>
<style
>
* {
padding
: 0;
margin
: 0;
list
-style
: none
;
}
table
{
margin
: 0 auto
;
margin
-top
: 50px
;
}
td
{
width
: 100px
;
text
-align
: center
;
line
-height
: 30px
;
}
button
{
border
-radius
: 5px
;
color
: white
;
background
-color
: rgb(139, 29, 29);
}
</style
>
</head
>
<body
>
<div
class="container">
</div
>
<script src
="../JQ/JQuery.js"></script
>
<script
>
$(function () {
let arr
= [{
id
: 1,
name
: 'Simba',
age
: 20
},
{
id
: 2,
name
: 'Jandy',
age
: 18
},
{
id
: 3,
name
: 'Ace',
age
: 19
}
]
let table
= $('<table/>')
let th1
= $('<th/>').html('编号')
let th2
= $('<th/>').html('姓名')
let th3
= $('<th/>').html('年龄')
let th4
= $('<th/>').html('操作')
let thead
= $('<tr/>').append(th1
).append(th2
).append(th3
).append(th4
)
table
.append(thead
)
arr
.forEach(r
=> {
let tr
= $('<tr/>')
Object
.values(r
).forEach(v
=> {
let td
= $('<td/>').html(v
)
tr
.append(td
)
})
let button
= $('<button/>').html('删除').addClass('del')
let td
= $('<td/>').html(button
)
tr
.append(td
)
table
.append(tr
)
})
$('.container').append(table
)
$('.del').click(function(){
$(this).parents('tr').remove()
})
})
</script
>
</body
>
</html
>
转载请注明原文地址:https://ipadbbs.8miu.com/read-5967.html