天气

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>天气信息查询</title>   
    <style type="text/css">
        
        .weather{
            width: 60px;
            padding-left: 8px;
            display: inline-block;
        }
        
		#tip {
			background-color: #fff;
			padding-left: 10px;
			padding-right: 10px;
			position: absolute;
			font-size: 10px;
			right:0px;
			top: 0px;
			border-radius: 3px;
			border: 1px solid #ccc;
			line-height: 30px;
		}


    </style>
    
</head>
<body>
    
<div id="tip" style="line-height: 12px"></div>
    
<script src="http://webapi.amap.com/maps?v=1.4.2&key=6202c32e3dccbecd6d7251d9f396db30&plugin=AMap.PolyEditor,AMap.CircleEditor,AMap.MouseTool,AMap.ToolBar,AMap.Driving"></script>
<script type="text/javascript" src='http://webapi.amap.com/maps?v=1.4.6&key=6202c32e3dccbecd6d7251d9f396db30&plugin=AMap.TruckDriving'></script> 
<script type="text/javascript" src="http://139.224.44.115:8010/Resource/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript">
weather()
    function weather()//天气查询方法
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
             //此句返回天气查询原始json数据
			 debugger
            var weatherinfo = xmlhttp.responseText;
            var text = JSON.parse(weatherinfo);
            var data = text.lives[0]; 
            var str = [];
             
                str.push('<div>城市/区:' + data.city + '</div>');
                str.push('<div>天气:' + data.weather + '</div>');
                str.push('<div>温度:' + data.temperature + '℃</div>');
                str.push('<div>风向:' + data.winddirection + '</div>');
                str.push('<div>风力等级:' + data.windpower + '</div>');
                str.push('<div>空气湿度:' + data.humidity + '</div>');
                str.push('<div>发布时间:' + data.reporttime + '</div>');
                document.getElementById('tip').innerHTML = str.join('<br>');
             
            //data数据类型为json  实例:
            // {"province" :"北京",
            //"city" :"东城区",
            //"adcode" :"110101",
            // "weather" :"晴",
            // "temperature" :"23",
            // "winddirection" :"北",
            // "windpower" :"9",
            // "humidity" :"15",
            //"reporttime" :"2017-04-18 16:00:00"}

        }
    }
    xmlhttp.open("GET","http://restapi.amap.com/v3/weather/weatherInfo?key=b90d81e4db390ecc709454bd5b30d487&address&city=310000",true);
    xmlhttp.send();
}

            
           
      

</script>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值