[英]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>
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.