简体   繁体   English

我在 div 中有输入,为什么我的代码使用 arrays 而不是值数组创建数组

[英]I have inputs in div why my code makes Array with arrays instead of array of value

I have a form with many inputs each on in div i need to make and array of input values instead of array of arrays with values.我有一个表单,其中每个输入都在 div 中,我需要创建输入值数组,而不是带有值的 arrays 数组。

 var arr = [].map.call(document.querySelectorAll(".form__option"), function(block) { return [].map.call(block.querySelectorAll(".field"), function(inp) { return inp.value;
 <div id='form__option3' class="form__option form__option3"> <input id="Input NameShipper" type="text" class="InputReciever field" /> </div>

  • Why don't you just directly select the inputs by class then push their values inside array你为什么不直接 select 输入 class 然后将它们的值推入数组
var InputReciever = document.getElementsByClassName("InputReciever");
var arr = []
for(let i = 0; i < InputReciever.length; i++) { 
  arr.push(InputReciever[i].value);
}
console.log(arr)

querySelectorAll , returns a nodeList ie an Array , you might wanna map it's data to values (with inp.value) and spread it like this. querySelectorAll ,返回一个nodeList即一个Array ,你可能想要 map 它的数据值(使用 inp.value)并像这样传播它。 return...mapedValues

暂无
暂无

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

相关问题 为什么我的代码返回数组的最后一个值而不是为每个项目返回结果? - Why is my code returning the last value of an array instead of returning a result for each item? 我想将图像放入 <div> 代替图像数组 - I want to put my images in a <div> instead of an image array nodejs 为什么我的代码返回 [object Object] 而不是数组? - nodejs why is my code returning [object Object] instead of an array? 为什么有一个观察者而不是我的数组? - Why is there an Observer instead of my array? 数组数组-为什么我的数组比我想象的还要多? - Array of arrays - why I have one more level of Arrays than I think I should? JavaScript 中的 Arrays - 如何将扫描的值保存在数组中 - Arrays in JavaScript - How can I save my scanned value in an array 在$ provide.decorator中更改输入值时,为什么我的角度形式不脏? - why my angular form is not dirty when I have changed inputs value in my $provide.decorator? 如何从数组数组中提取在第一个字段中具有相同值的所有数组? - How can I extract from an array of arrays all the arrays that have the same value in their first field? 如何遍历 arrays 数组并检查它们是否具有另一个数组 + 前缀的值? - How can I iterate through array of arrays and check if they have a value of another array + prefix? 合并 arrays,为什么我的输入数组发生了变异? - Merging arrays, why is my input array mutated?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM