首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我想在图片的路径中写图标名<img source="">标记

我想在图片的路径中写图标名<img source="">标记
EN

Stack Overflow用户
提问于 2019-08-02 07:20:01
回答 1查看 60关注 0票数 1

我使用黑暗天空API来获取天气信息和图标参数给我多云,部分多云,阳光等。我保存图标图像与图标名称在文件夹中相同的名称。我想在源路径中写入这个参数,如下所示

代码语言:javascript
运行
复制
 <img src="..\..\icon\weather\  $forecast.weatherDays[0].icon .png" height="300vh" width="300vw">

weather.html

代码语言:javascript
运行
复制
  <div id="day1"> <div id="icon"></div> </div>
 <div id="day2"> <div id="icon"></div> </div>

weatherManager.js

代码语言:javascript
运行
复制
document.querySelector("#day1 #icon").innerHTML=forecast.weatherDays[0].icon;
document.querySelector("#day2 #icon").innerHTML=forecast.weatherDays[0].icon;

我怎么能这么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-02 07:37:01

您需要使用以下代码在div中添加图像:

代码语言:javascript
运行
复制
var forecast = {};
forecast.weatherDays = [];

forecast.weatherDays[0]= { icon :'partly-cloudy'};
forecast.weatherDays[1]= { icon :'image8-2'};

//console.log(forecast.weatherDays)

document.querySelector("#day1 #icon").innerHTML= '<img src="..\\..\\icon\\weather\\'+forecast.weatherDays[0].icon+'.png" height="300vh" width="300vw">';

 document.querySelector("#day2 #icon").innerHTML= '<img src="https://blog.hubspot.com/hubfs/'+forecast.weatherDays[1].icon+'.jpg" height="300vh" width="300vw">';
代码语言:javascript
运行
复制
 <div id="day1"> <div id="icon"></div> </div>

 <div id="day2"> <div id="icon"></div> </div>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57321643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档