This commit is contained in:
rou
2026-03-23 14:56:04 +08:00
parent 00d3c9e4c6
commit 1071f4db05
27 changed files with 549 additions and 50 deletions

View File

@@ -1,5 +1,5 @@
const loadButton = document.getElementById("load-btn");
const status = document.getElementById("status");
const status1 = document.getElementById("status");
const output = document.getElementById("output");
// 任务:
@@ -9,3 +9,17 @@ const output = document.getElementById("output");
// 4. 调用 res.json() 解析数据
// 5. 把 title 和 body 渲染到页面
// 6. 失败时显示“加载失败”
loadButton.addEventListener("click", async () => {
status1.textContent = "加载中..."
try {
let a = await fetch("https://jsonplaceholder.typicode.com/posts/1")
let data = await a.json()
status1.textContent = "加载成功"
const { title, body } = data
output.textContent = `title:${title}
body:${body}`
} catch (error) {
status1.textContent = "加载失败"
}
})