document.addEventListener("DOMContentLoaded", () => { fetch("/api/swimming-tips") .then(response => response.json()) .then(data => { const tipsList = document.getElementById("tips-list"); data.tips.forEach(tip => { const tipDiv = document.createElement("div"); tipDiv.classList.add("tip"); const tipTitle = document.createElement("h3"); tipTitle.textContent = tip.title; tipDiv.appendChild(tipTitle); const tipDescription = document.createElement("p"); tipDescription.textContent = tip.description; tipDiv.appendChild(tipDescription); tipsList.appendChild(tipDiv); }); }) .catch(error => { console.error("获取数据时出错:", error); }); });