我在选择带有名称数组的输入字段时遇到问题,其中包含来自行的其余元素:input,select,textarea。我正在做以下事情:
$(".UpdateMe").click(function() {
var id = $(this).attr("id");
var row_id = $("#trCharges" + id);
var row = {};
$(row_id).find('input,select,textarea').each(function() {
row[$(this).attr('name')] = $(this).val();
});
console.log(row);
});
上述代码适用于没有名称作为数组的元素。对于带有name数组的输入它只获取最后一个值。我想从行中获取所有内容,包括名称数组,即带有name="anarray[]
"的字段。
I could separate get each of those input with name array like these:
aname = [];
$(row_id).find(".NameArray").each(function() {
aname.push({
name: $(this).attr('name'),
value: $(this).val()
});
});
But, I would like to know how to do all together.
有什么想法吗?
答案 0 :(得分:0)
I ended up using serializeArray() to get all elements from the row.
{{}}
This gave me all values to include those with name array. It is easier than doing it by hand which still don't know how to do it.