我的网页中有一个表格(带有两个文本框“项目”和“计数”)。
我尝试访问每行中两个文本框的值。
请参阅下面的代码
<table id="tbl-contents" class="table">
<thead>
<tr>
<th>Item</th>
<th>Count</th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="clsRow">
<td>
@*
<input type="text" class="form-control" placeholder="Item" data-required="true">*@
<input id="txtItem" class="form-control" placeholder="Item" type="text" value="" tabindex="-1" name="" data-required="true">
</td>
<td>
@*
<input type="text" class="form-control" placeholder="Item Count" data-required="true">*@
<input id="txtItemCount" class="form-control" placeholder="Item Count" type="text" value="" tabindex="-1" name="" data-required="true">
</td>
</tr>
<tr class="clsRow">
<td>
<input type="text" class="form-control" placeholder="Item">
</td>
<td>
<input type="text" class="form-control" placeholder="Item Count">
</td>
<td>
<a class="clsDelContent"><i class="fa fa-minus-square" style="font-size: 22px;"></i></a>
</td>
</tr>
<tr class="clsRow">
<td>
<input type="text" class="form-control" placeholder="Item">
</td>
<td>
<input type="text" class="form-control" placeholder="Item Count">
</td>
<td>
<a class="clsDelContent"><i class="fa fa-minus-square" style="font-size: 22px;"></i></a>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3" style="text-align: right;">
<a class="clsAddContent"><i class="fa fa-plus-square" style="font-size: 22px;"></i></a>
</td>
</tr>
</tfoot>
</table>
脚本
$('#tbl-contents tbody tr').each(function () {
var customerId = $(this).find("td").html();
alert(customerId);
});
最佳答案
$('.clsRow').each(function() {
var foo = $(this).find('input');
var item = foo[0].value;
var itemcount = foo[1].value;
})
关于c# - 如何获取表格内的文本框值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24305620/