天气预报24小时实时查询明天 (天气预报24小时查询)
长沙娱乐
07-29
阅读:2
评论:4
![](/gg/hf11.gif)
请输入您的城市名称:
script.js
javascript
// 获取元素
const searchBtn = document.getElementById('search-btn');
const result = document.getElementById('result');// 添加查询事件监听器
searchBtn.addEventListener('click', function() {// 获取城市名称const cityName = document.getElementById('city-name').value;// 向OpenWeatherMap API发送请求const url = `${cityName}&appid=YOUR_API_KEY`;fetch(url).then(response => response.json()).then(data => {// 解析数据并显示结果const weatherData = data.weather[0];const temperature = Math.round(data.main.temp - 273.15);const description = weatherData.description;const icon = `${weatherData.icon}@2x.png`;result.innerHTML = `
${cityName}
![天气预报24小时实时查询明天 (天气预报24小时查询)](https://tgirlmeat.com/thumb/20240729161707_71773.jpg)
温度:${temperature} °C
天气:${description}
查询失败,请检查城市名称是否正确。
';}); });版权声明
本文仅代表作者观点,不代表长沙桑拿立场。
本文系作者授权发表,未经许可,不得转载。