【问题标题】:Simpleweather.js - icons for forecast itemsSimpleweather.js - 预报项目的图标
【发布时间】:2015-02-05 05:48:52
【问题描述】:

我正在使用 simpleweather.js 成功呈现天气更新,并试图让预报图标出现在预报日旁边。

使用:

$(document).ready(function() {
  $.simpleWeather({
  location: 'Melborune, Australia',
  unit: 'c',
  success: function(weather) {
  html = '<h2><i class="icon-'+weather.code+'"></i>'+weather.temp+'&deg;'+weather.units.temp+'</h2>';
  html += '<ul><li><i style="color:#000" class="icon-'+weather.code+'"></i>'+weather.city+', '+weather.region+'</li>';
  html += '<li class="currently">'+weather.currently+'</li>';
  html += '<li>'+weather.alt.temp+'&deg;C</li></ul>';

  for(var i=0;i<weather.forecast.length;i++) {
    html += '<p><i style="color:#000" class="icon-'+weather.code+'"></i>'+weather.forecast[i].day+': '+weather.forecast[i].high+'</p>';
  }

  $("#weather").html(html);
    },
    error: function(error) {
      $("#weather").html('<p>'+error+'</p>');
    }
  });
});

我可以四处走动,它会显示当前温度的图标,但我不知道预测天数的图标代码是什么。

对不起,我对使用 API 很陌生。任何帮助将不胜感激。

【问题讨论】:

    标签: jquery weather


    【解决方案1】:

    forecast[X].image 返回 X 天条件码的全尺寸图片 url。希望这就是你的意思,伙计.. :)

    $(document).ready(function () {
        $.simpleWeather({
            location: 'Melborune, Australia',
            unit: 'c',
            success: function (weather) {
                html = '<h2><i class="icon-' + weather.code + '"></i>' + weather.temp + '&deg;' + weather.units.temp + '</h2>';
                html += '<ul><li><i style="color:#000" class="icon-' + weather.code + '"></i>' + weather.city + ', ' + weather.region + '</li>';
                html += '<li class="currently">' + weather.currently + '</li>';
                html += '<li>' + weather.alt.temp + '&deg;C</li></ul>';
    
                for (var i = 0; i < weather.forecast.length; i++) {
                    img = '<img style="float:left;" width="125px" src="' + weather.forecast[i].image + '">';
                    html += '<p>' + img + '<i style="color:#000" class="icon-' + weather.code + '"></i>' + weather.forecast[i].day + ': ' + weather.forecast[i].high + '</p>';
                }
    
                $("#weather").html(html);
            },
            error: function (error) {
                $("#weather").html('<p>' + error + '</p>');
            }
        });
    });
    

    小提琴here

    【讨论】:

    • 正是我所追求的,谢谢大家...我整个下午都在绞尽脑汁。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多