You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.0 KiB

1 month ago
document.addEventListener("DOMContentLoaded", () => {
fetch("/api/python-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);
const tipExample = document.createElement("pre");
tipExample.textContent = tip.example;
tipDiv.appendChild(tipExample);
tipsList.appendChild(tipDiv);
});
})
.catch(error => {
console.error("获取数据时出错:", error);
});
});