【发布时间】:2026-01-16 01:15:02
【问题描述】:
我有一张表,在该表中我有id="edit" 的值。现在,我想要的是在单击任何单元格时获取相应列的标题名称。到目前为止,根据之前提出的问题,我所拥有的是:
$('body').on('click', 'td#edit', function() {
var th = $('this').closest('th').eq($('th').val());
alert(th); // returns [object Object]
.........................
}
你能帮我解决这个问题吗?
HTML:
<table id="myTable" class="myTable">
<tbody>
<tr>
<th>Select</th>
<th>JobNo</th>
<th>Customer</th>
<th>JobDate</th>
<th>Warranty</th>
<th>RepairStatus</th>
<th>POP</th>
<th>DOA</th>
<th>Model</th>
<th>SN</th>
</tr>
<tr>
<td class="check">
<input type="checkbox" value="12345">
</td>
<td class="edit">
<b>12345</b>
</td>
<td class="edit">gdsgasdfasfasdfa</td>
<td class="edit">2011-01-21</td>
<td class="edit">TRUE</td>
<td class="edit">RP</td>
<td class="edit">FALSE</td>
<td class="edit">0</td>
<td class="edit">5152342</td>
<td class="edit">66665464</td>
</tr>
</tbody>
【问题讨论】:
-
你不应该有
values和id=editid 应该是唯一的 -
你是否多次使用同一个id?你用
id="edit"写了你有价值s。 ID 应该是唯一的 -
HTML标记是什么?? -
'id' 应该始终是唯一的。你不能把 id="edit" 给所有的 td。
-
不管是class还是id,都解决不了我的问题。那不是我问的问题
标签: jquery html-table cell