zoukankan      html  css  js  c++  java
  • 天气获取

     $.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

  • 相关阅读:
    bootstrap2文档的学习
    在mininet上基于ovs,ovx,pox搭建三点虚拟网络
    借鉴一些关于js框架的东西
    setTimeout js
    Ubuntu 上配置静态的ip
    html5 canvas
    获取当前页面的长宽
    ovs的卸载
    tensorflow实现Word2vec
    梯度下降做做优化(batch gd、sgd、adagrad )
  • 原文地址:https://www.cnblogs.com/tangchun/p/7839449.html
Copyright © 2011-2022 走看看