我想获取动态表中的所有td值,但是使用我的代码,我只能在没有td输入的情况下获得第一列(Id),
我的桌子:
<table class="table table-bordered table-hover" id="tab_4">
<thead>
<tr>
<th class="text-center 1 bg-info text-white"> # </th>
<th class="text-center col-xs-3 bg-info text-white"> Producto </th>
<th class="text-center col-xs-3 bg-info text-white"> Cant </th>
<th class="text-center col-xs-3 bg-info text-white"> Precio </th>
<th class="text-center col-xs-3 bg-info text-white"> Total </th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td>1</td>
<td><input type="text" name='product[]' placeholder='Ing. nombre de prod.' class="form-control"/></td>
<td><input type="number" name='qty[]' placeholder='Ing. Cant' class="form-control qty" step="0" min="0"/></td>
<td><input type="number" name='price[]' placeholder='Ing. precio unit' class="form-control price" step="0.00" min="0"/></td>
<td><input type="number" name='total[]' placeholder='0.00' class="form-control total" readonly/></td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
我的JQuery:
function sendtable() {
var tabla4 = [];
$("table#tab_4 tr").each(function () {
var arrayOfThisRow = [];
var tableData = $(this).find("td");
if (tableData.length > 0) {
tableData.each(function () {
arrayOfThisRow.push($(this).text());
});
tabla4.push(arrayOfThisRow);
}
});
google.script.run.insertarFilas(tabla4);
alert(tabla4);}
知道我在做什么错吗?