收集几个输入字段并使用jquery插入单个字段 [英] Collect several input fields and insert into a single field with jquery
问题描述
我有4个输入文本字段,以及一个应从每个文本字段中收集值的单个文本字段.
I have 4 input textfields, and a single textfield that should collect values from each.
<input type="text" class="collector">
<input type="text" class="collected">
<input type="text" class="collected">
<input type="text" class="collected">
<input type="text" class="collected">
收集的输入是文本,应原样插入收集器. 因此,也应该将NULL与带有值的NULL一起发送.
The collected inputs are text and expected to be inserted into collector as is. So NULL should be sent too along with those with values.
收藏家希望看起来像: 数据1 |空|数据3 |数据4
The collector expects to look like: Data 1 | Null | Data 3 | Data 4
因此,在不提供任何值的情况下,可以接受Null,只是为了维持PHP爆炸和内爆的过程.
So Null is accepted when no value is given, simply to maintain the process of explode and implode by PHP.
我被困住了,我的jquery只选择了其中一个,因为我不知道如何将单独收集的值聚合到一个数组中:
I am stuck, my jquery only picks one of them, because I don't know how to aggregate the separate collected values into an array:
$('input.collector').val($(".collected").text());
任何提示都非常感谢.谢谢
Any hint is very much appreciated. Thanks
推荐答案
尝试一下:
$('input.collector').val(function() {
return $(".collected").map(function() {
return $(this).val() || 'NULL';
}).get().join('|');
});
这篇关于收集几个输入字段并使用jquery插入单个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!