用图像创建DIV
我正在尝试浏览数组的每个元素,并且对于每个链接,创建一个照片div。 我应该使用image.src
什么?我不确定。
list.forEach((x) => {
var image = document.createElement("img");
image.src = ;
image.className = "queryImg";
document.getElementById("queryResults").appendChild(image);
});
I am trying to create divs from an array of links of photos. This is what the array looks like
I am trying to go through each element of the array and for each link create a photo div.
What should I use a image.src
? I am not sure about that.
list.forEach((x) => {
var image = document.createElement("img");
image.src = ;
image.className = "queryImg";
document.getElementById("queryResults").appendChild(image);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还将浏览链接,以确保它们是图像文件。
I would also browse the links, to make sure they are image files.
image.src = x;
是否有效?在您的
foreach
中,x
作为数组中的迭代元素传递,因此可以使用该元素检索实际数据Does
image.src = x;
work?In your
forEach
,x
is being passed as the iterated element in the array so the actual data would be retrieved using that