update
This commit is contained in:
@@ -4,3 +4,17 @@
|
||||
// 3. 用 preventDefault() 阻止默认提交
|
||||
// 4. 读取输入框内容,创建新 li,追加到列表
|
||||
// 5. 清空输入框
|
||||
const form = document.getElementById("todo-form")
|
||||
const input = document.getElementById("todo-input")
|
||||
const list = document.getElementById("todo-list")
|
||||
|
||||
form.addEventListener("submit", function (e) {
|
||||
e.preventDefault()
|
||||
const text = input.value.trim()
|
||||
if (text) {
|
||||
const li = document.createElement("li")
|
||||
li.textContent = text
|
||||
list.appendChild(li)
|
||||
input.value = ""
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user