我有一个表格,前两个单元格是inputfields,我试图映射数组内的所有表格数据。但我不知道如何从输入字段获取数据,知道它只映射其他数据。带输入字段的jQuery map()表
<table width="100%">
<thead>
<tr>
<td><strong>Amount</strong></td>
<td><strong>Price</strong></td>
<td><strong>Articleid</strong></td>
<td><strong>Descr</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td><input class="amount" type="text" value="1"></td>
<td><input class="purchprice" type="text" value="2.00"></td>
<td>210003</td>
<td>Example_1</td>
</tr>
<tr>
<td><input class="amount" type="text" value="1"></td>
<td><input class="purchprice" type="text" value="19.25"></td>
<td>128025</td>
<td>Example_2</td>
</tr>
<tr>
<td><input class="amount" type="text" value="3"></td>
<td><input class="purchprice" type="text" value="23.45"></td>
<td>124005</td>
<td>Example_3</td>
</tr>
</tbody>
</table>
jQuery的
<button type="button" class="map">Map table</button>
$('.map').on('click', function() {
var tableData = $('table tbody td').map(function() {
return $(this).text();
}).get();
console.log($.trim(tableData[0]));
console.log($.trim(tableData[1]));
console.log($.trim(tableData[2]));
console.log($.trim(tableData[3]));
});
'$回报(本)。是( ':有(:输入)')$(?:输入“,这).val():$(this).text();' –
太好了!谢谢 – Bart
很高兴帮助你:) –