如何从每个输入字段中提取一个字符串并将它们放置在同一数组中?
我当前拥有的代码是这个。.
in xaml
xmlns:effects="clr-namespace:YourApp.Effects"
<ListView>
<ListView.Effects>
<effects:ListViewEffect/>
</ListView.Effects>
...
</ListView>
or in the CS file
_listView.Effects.Add(Effect.Resolve("YourApp.ListViewEffect"));
var input1 = document.querySelector('.form');
var btn = document.getElementById('btn');
var array = [];
btn.addEventListener('click', function(){
array.push(input.value);
console.log(array);
});
先谢谢了。
答案 0 :(得分:2)
使用Array.from
选择带有.form
的所有querySelectorAll
,并传递一个映射函数,该函数从每个.value
中提取const inputs = document.querySelectorAll('.form');
var btn = document.getElementById('btn');
btn.addEventListener('click', function(){
const arr = Array.from(inputs, elm => elm.value);
console.log(arr);
});
:
<div class="container mt-5">
<div class="row">
<div class="col-lg-12 text-center">
<input type="text" class="form">
</div>
</div>
</div>
<div class="container mt-5">
<div class="row">
<div class="col-lg-12 text-center">
<input type="text" class="form">
</div>
</div>
</div>
<button class="btn btn-primary text-center" id="btn">SUBMIT</button>
memcpy()