简易天气预报代码

 <!DOCTYPE html>
 <html lang="en">
 <head>
 <meta charset="UTF-8">
 <title>Title</title>
 <style>
 #show{display:block;width:800px;height:200px;background:orange;border:1px solid #333;}
 </style>
 </head>
 <body>
 <input type="text" id="city">
 <button id="checkWeather">查询天气</button><br />
 <span id="show">展示天气预报</span>
  
 <script>
 var cw = document.getElementById("checkWeather");
 cw.onclick = function() {
 var http;
 if(window.XMLHttpRequest) {
 http = new XMLHttpRequest();
 } else {
 http = new ActiveXObject("Microsoft.XMLHTTP");
 }
  
 http.onreadystatechange = function(){
 if(http.readyState == 4 && http.status == 200) {
 // show.textContent = http.responseText;
 var json = JSON.parse(http.responseText);
 console.log(json);
 show.textContent = "城市:" + json.data.city;
 show.textContent += "===温馨提示:" + json.data.ganmao;
 show.textContent += "===今天天气:" + json.data.forecast[0].type;
 show.textContent += ",最低温度:" + json.data.forecast[0].low;
 show.textContent += ",最高温度:" + json.data.forecast[0].high;
 show.textContent += ",风力:" + json.data.forecast[0].fengli;
 show.textContent += ",风向:" + json.data.forecast[0].fengxiang;
 }
 }
  
 var cityName = city.value;
  
 http.open("GET", "http://wthrcdn.etouch.cn/weather_mini?city=" + cityName,true);
 http.send();
 }
 </script>
 </body>
 </html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值