用图像创建DIV

发布于 2025-02-01 18:15:05 字数 496 浏览 1 评论 0原文

我正在尝试从一系列照片链接中创建Divs。这就是阵列的样子

我正在尝试浏览数组的每个元素,并且对于每个链接,创建一个照片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
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开柳相依 2025-02-08 18:15:05

我还将浏览链接,以确保它们是图像文件。

list.forEach((x) => {
      var image = document.createElement("img");
      image.src = x;
      image.className = "queryImg";
      document.getElementById("queryResults").appendChild(image);
});

I would also browse the links, to make sure they are image files.

list.forEach((x) => {
      var image = document.createElement("img");
      image.src = x;
      image.className = "queryImg";
      document.getElementById("queryResults").appendChild(image);
});
耳钉梦 2025-02-08 18:15:05

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文