小编vul*_*gim的帖子

jQuery获取带有id的单击单元格的表头名称

我有一张桌子,在那张桌子里我有价值观id="edit".现在,我想要的是当我点击任何单元格时获取相应列的标题名称.根据先前提出的问题,我到目前为止所得到的是:

$('body').on('click', 'td#edit', function() {  
    var th = $('this').closest('th').eq($('th').val());
    alert(th);        // returns [object Object]
    .........................
}
Run Code Online (Sandbox Code Playgroud)

你能帮我解决这个问题吗?

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>
Run Code Online (Sandbox Code Playgroud)

jquery html-table cell

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

cell ×1

html-table ×1

jquery ×1