• 天气获取


     $.get("http://wthrcdn.etouch.cn/WeatherApi", { citykey: cityCode }, function (d) {
                //创建文档对象
                var parser = new DOMParser();
                var xmlDoc = parser.parseFromString(d, "text/xml");
                var cityList = xmlDoc.getElementsByTagName('city');
                var city = $(cityList[0]).text();
                var weatherList = xmlDoc.getElementsByTagName('weather');
                var $weather = $(weatherList[0]);
                var date = $weather.children("date").text();//时间
                var high = $weather.find("high").text();//最高气温
                var low = $weather.find("low").text();//最低气温
                var dayType = $weather.find("day type").text();//白天天气
                var nightType = $weather.find("night type").text();//晚上天气
                var html = city + "<label style='10px;'></label>"
                    + "白天:" + dayType + ",晚上:" + nightType
                    + "<label style='10px;'></label>"
                    + low
                    + "<label style='10px;'></label>"
                    + high;
                var aWeather = document.getElementById("aWeather");
                aWeather.innerHTML = html;
                aWeather.setAttribute("href", "http://www.weather.com.cn/weathern/" + cityCode + ".shtml");
            });

    接口调用:

    http://wthrcdn.etouch.cn/WeatherApi?city=昆明

    或者

    http://wthrcdn.etouch.cn/WeatherApi?citykey=citycode

  • 相关阅读:
    poj 2251
    poj 1321
    poj 2777
    poj 3468
    poj 2318
    javascript
    buhui
    swift 构造器
    mac上不了网
    字体
  • 原文地址:https://www.cnblogs.com/tangchun/p/7839449.html
Copyright © 2020-2023  润新知