Я хочу взять значение из динамической таблицы и отправить значение в вызове ajax, я динамически увеличиваю строку таблицы, но когда я пытаюсь взять значение строки в массив, он сохраняет только значение первой строки.
Мой HTML-код:
<table class="table table-bordered table-hover table-sm" id="SizeTable">
<thead>
<tr>
<th><input type="checkbox" class="allGridCheck"></th>
<th style="width: 50%;">Size</th>
<th style="width: 50%;">Quantity</th>
<th class="hidden"></th>
</tr>
</thead>
<tbody class="GridContent table-secondary" id="GridBody">
<tr class="GridFields">
<td><input type="checkbox" class="singleGridCheck"></td>
<td>
<select class="form-control form-control-sm size-id" name="SizeId"></select>
</td>
<td>
<input type="number" class="form-control form-control-sm quantity-value" name="QuantityValue" />
</td>
<td class="hidden"></td>
</tr>
</tbody>
А вот мой сценарий:
var sizesId = [];
var sizesValue = [];
$('#SizeTable > tbody > tr').each(function() {
var sizeId = $('.size-id option:selected').val();
var sizeValue = $('.quantity-value').val();
if (sizeId) {
sizesId.push(sizeId);
}
if (sizeValue) {
sizesValue.push(sizeValue);
}
alert(sizeId);
});
alert(sizesId);
alert(sizesValue);
Как мне взять значение в массив ???