【发布时间】:2019-07-30 22:21:44
【问题描述】:
我有一个看起来像的
<div class="book-form">
<input type="text" id="book_qty" name="book_qty[0]" value="" >
<input type="text" id="book_unit" name="book_unit[0]" value="" >
<input type="text" id="book_name" name="book_name[0]" value="" >
<input type="text" id="book_notes" name="book_notes[0]" value="" >
<input type="text" id="book_qty" name="book_qty[1]" value="" >
<input type="text" id="book_unit" name="book_unit[1]" value="" >
<input type="text" id="book_name" name="book_name[1]" value="" >
<input type="text" id="book_notes" name="book_notes[1]" value="" >
</div>
然后我有一个数组,其中包含与上述表单相同的映射值
0: Array(4)
0: "1 "
1: "boxes "
2: "Math"
3: "in Stock"
length: 4
1: Array(4)
0: "2 "
1: "boxes "
2: "science "
3: " "
length: 4
我正在尝试遍历数组并分别更新表单字段。
这是我尝试过的代码
var all_inputs = $(".autofill input[type=text]");
$(all_inputs).each(function() {
$.each(myTableArray, function (n, elem) {
console.log(elem);
all_inputs.val(elem);
});
});
但这会用相同的最后一个值填充表单。
请帮忙。
【问题讨论】:
-
ID 应该是唯一的,你不应该有多个
id="book_qty"。