如何使用jQuery获取表单元格值?我正在尝试如何使用jQuery为每行获取表单元格的值。我的桌子是这样的:<table id="mytable">
<tr>
<th>Customer Id</th>
<th>Result</th>
</tr>
<tr>
<td>123</td>
<td></td>
</tr>
<tr>
<td>456</td>
<td></td>
</tr>
<tr>
<td>789</td>
<td></td>
</tr></table>基本上,我希望遍历该表,并获得Customer Id每一行的列。在下面的代码中,我已经计算出我需要这样做才能让它在每一行中循环,但是我不知道如何获得行中第一个单元格的值。$('#mytable tr').each(function() {
var cutomerId = }
3 回答
达令说
TA贡献1821条经验 获得超6个赞
$('#mytable tr').each(function() {
var customerId = $(this).find(".customerIDCell").html();
});<span>
$('#mytable .customerIDCell').each(function() {
alert($(this).html());});
慕桂英4014372
TA贡献1871条经验 获得超13个赞
$('#mytable tr').each(function() {
var customerId = $(this).find("td:first").html(); });$('#mytable tr').each(function() {
var customerId = $(this).find("td").eq(2).html(); });var table = document.getElementById('mytable'),
rows = table.getElementsByTagName('tr'),
i, j, cells, customerId;for (i = 0, j = rows.length; i < j; ++i) {
cells = rows[i].getElementsByTagName('td');
if (!cells.length) {
continue;
}
customerId = cells[0].innerHTML;}
江户川乱折腾
TA贡献1851条经验 获得超5个赞
$('#mytable tr').each(function() {
if (!this.rowIndex) return; // skip first row
var customerId = this.cells[0].innerHTML;});- 3 回答
- 0 关注
- 707 浏览
添加回答
举报
0/150
提交
取消
