update
This commit is contained in:
@@ -1,4 +1,22 @@
|
||||
// 任务:
|
||||
// 1. 获取新增按钮、删除按钮和列表
|
||||
// 2. 点击新增按钮时创建一个新的 li 并追加到列表
|
||||
|
||||
|
||||
|
||||
|
||||
// 3. 点击删除按钮时删除最后一个 li
|
||||
const add = document.getElementById("add-btn")
|
||||
const remove = document.getElementById("remove-btn")
|
||||
const list = document.getElementById("task-list")
|
||||
add.onclick = function () {
|
||||
const a = document.createElement("li")
|
||||
a.textContent = "巧克力"
|
||||
list.appendChild(a)
|
||||
}
|
||||
remove.onclick = function () {
|
||||
const c = list.lastElementChild
|
||||
if (c) {
|
||||
c.remove()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user