简体   繁体   English

如何将包含附加到 URL 的变量的 arrays 放入图像占位符中? JavaScript

[英]How do I put arrays which consist of variables that are attached to URL's into image placeholders? JavaScript

var imagesID = ["Image1", "Image2", "Image3", "Image4", "Image5", "Image6"];

function setImage() {
  for (var i = 0; i < gardenList.length; i++) {
    image(imagesID[i]++, gardenList[i]++);
  }
} 

gardenList consists of a list of variables that are chosen by the user and are added to the end of an array as the user checks boxes. gardenList 由用户选择的变量列表组成,并在用户选中复选框时添加到数组的末尾。 What I'm having trouble with is that when the function loops for as long as the length of gardenList.Length, the program says that image() id parameter value (NaN) is not a string.我遇到的问题是,当 function 循环的长度与 gardenList.Length 的长度一样长时,程序说 image() id 参数值 (NaN) 不是字符串。 "Image1" and so on are the IDs for image placeholders. “Image1”等是图像占位符的 ID。 The variables in gardenList consist of URLs and would look something like this: gardenList 中的变量由 URL 组成,看起来像这样:

var lettuce = " https://bhvifbvijcncjowcw " gardenList = [lettuce, ...] Does anyone know how to resolve this issue? var lettuce = " https://bhvifbvijcncjowcw " gardenList = [lettuce, ...] 有谁知道如何解决这个问题?

You are adding unnecessary ++ in the loop.您在循环中添加了不必要的++ This should work这应该工作

 var imagesID = ["Image1", "Image2", "Image3", "Image4", "Image5", "Image6"]; function setImage() { for (var i = 0; i < gardenList.length; i++) { image(imagesID[i], gardenList[i]); } }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM