[英]I want to write icon names inside the paths of images <img source=“”> tag
I am using Dark Sky API to get weather information and icon parameter gives me cloudy, partly-cloudy, sunny etc. I saved icon images same name with icon names in the folder. 我正在使用Dark Sky API获取天气信息,并且图标参数使我多云,部分多云,晴天等。我在文件夹中保存了具有相同图标名称的图标图像。 I want to write this parameter inside the source path like
我想在源路径中写入此参数,例如
<img src="..\..\icon\weather\ $forecast.weatherDays[0].icon .png" height="300vh" width="300vw">
weather.html weather.html
<div id="day1"> <div id="icon"></div> </div>
<div id="day2"> <div id="icon"></div> </div>
weatherManager.js weatherManager.js
document.querySelector("#day1 #icon").innerHTML=forecast.weatherDays[0].icon;
document.querySelector("#day2 #icon").innerHTML=forecast.weatherDays[0].icon;
How can I do that? 我怎样才能做到这一点?
you need to add the image inside the div using the following code: 您需要使用以下代码在div中添加图片:
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">';
<div id="day1"> <div id="icon"></div> </div> <div id="day2"> <div id="icon"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.