首先要去到对应网站的控制台,查看请求路径和参数,然后直接上源码,这里只展示js,对应的html元素不明白怎么写的话问下AI就行了。
document.addEventListener("DOMContentLoaded", function() { const textP = document.getElementById("text"); const weatherImg = document.getElementById("weatherImg"); const humidityP = document.getElementById("humidity"); const windDirP = document.getElementById("windDir"); const temp= document.getElementById("temp"); getResult(); function getResult() { const cityID = "101281001"; const url = `https://devapi.qweather.com/v7/weather/now?location=${cityID}&key=your_key`; fetch(url) .then(response => response.json()) .then(data => updateUI(data)) .catch(() => textP.innerHTML = "获取天气信息失败,请检查城市天气ID"); } function updateUI(data) { const { now } = data; textP.innerHTML = now.text; humidityP.innerHTML = now.humidity; windDirP.innerHTML = now.windDir; temp.innerHTML