【发布时间】:2017-11-07 09:50:41
【问题描述】:
我有一张如下表:
<table id="testTable" class="mainTable">
<thead>
<tr>
<th>Title</th>
<th>
Select All
<input type="checkbox" id="select_all">
</th>
</tr>
</thead>
<tbody>
<tr>
<td>Cell 1</td>
<td><input type="checkbox" class="checkbox"></td>
</tr>
<tr>
<td>Cell 2</td>
<td><input type="checkbox" class="checkbox"></td>
</tr>
<tr>
<td>Cell 3</td>
<td><input type="checkbox" class="checkbox"></td>
</tr>
<tr>
<td>Cell 4</td>
<td><input type="checkbox" class="checkbox"></td>
</tr>
</tbody>
</table>
目前,我的 JS 代码会从表格中获取所有第一个 td 元素,无论复选框如何,代码如下:
$("#testTable tr").each(function() {
firsttd += $(this).find("td:first").html() + "\n";
});
但是,我需要对此进行修改,以便我的 JS 代码仅获取选中复选框行的第一个 td 元素。
【问题讨论】:
标签: javascript jquery html dom checkbox