【问题标题】:linking png image from json to html [duplicate]将png图像从json链接到html [重复]
【发布时间】:2023-03-25 14:11:01
【问题描述】:

我相信您将亲眼看到,我在编码方面相对较新。我一直在努力从 json 文件中获取 png 图像以显示在我的 codepen 上。我已经尝试了在 Stackoverflow 搜索中找到的几个建议,但我尝试过的任何建议似乎都不适用于我的情况。

这是我的代码笔的链接: http://codepen.io/mbabaian/pen/MpjbZv

此时我试图用来获取图像的代码是:

    var currentIcon = wd.current.condition.icon;
         // weather icon settings
  $("#current-icon").html("<img src='wd.current.condition.icon' alt='weather icon'/> ");

这是图像所在的特定 json 数据:

https://api.apixu.com/v1/current.json?key=68629a769f564f9bb6450153170703&q=auto:ip

如果您需要我提供有关此的任何其他信息,请告诉我。提前致谢。

【问题讨论】:

    标签: javascript json


    【解决方案1】:

    简单地使用

    $("#current-icon").html("<img src='"+wd.current.condition.icon+"' alt='weather icon'/> ");
    

    这是您更新后的codepen

    【讨论】:

    • 谢谢!修复也很简单。
    【解决方案2】:

    你创建currentIcon,使用它

    $("#current-icon").html('<img src="'+currentIcon+'" alt="weather icon"/>');
    

    【讨论】:

    • 哈!这是我错过的+。谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2014-07-31
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-20
    • 2016-10-22
    相关资源
    最近更新 更多