广州天气预报 60 天查询
script.js
javascript
// 假设我们已经从某个数据源获取了天气数据,并将其存储在 `weatherData` 数组中。// 遍历天气数据并将其添加到 HTML 表格中
for (const data of weatherData) {const row = document.createElement('tr');const dateTd = document.createElement('td');dateTd.textContent = data.date;row.appendChild(dateTd);const weatherTd = document.createElement('td');weatherTd.textContent = data.weather;row.appendChild(weatherTd);const highTempTd = document.createElement('td');highTempTd.textContent = data.highTemp;row.appendChild(highTempTd);const lowTempTd = document.createElement('td');lowTempTd.textContent = data.lowTemp;row.appendChild(lowTempTd);const windDirTd = document.createElement('td');windDirTd.textContent = data.windDir;row.appendChild(windDirTd);const windSpeedTd = document.createElement('td');windSpeedTd.textContent = data.windSpeed;row.appendChild(windSpeedTd);document.getElementById('weather-table').appendChild(row);
}