繁体   English   中英

在具有行标题和列标题的表中,给定列标题文本和单元格文本,如何选择单元格(td)?

[英]In a table with row headers and column headers, given a column header text and a cell text, how can I select a cell (td)?

给定此表:

<table border>
    <tbody>
        <tr>
            <th></th>
            <th>A</th>
            <th>B</th>
            <th>C</th>
            <th>D</th>
        </tr>
        <tr>
            <th>B</th>
            <td id="i0j0">sa</td>
            <td id="i0j1">sa</td>
            <td id="i0j2">sb</td>
            <td id="i0j3">sa</td>
        </tr>
        <tr>
            <th>C</th>
            <td id="i1j0">sb</td>
            <td id="i1j1">sb</td>
            <td id="i1j2">sb</td>
            <td id="i1j3">sb</td>
        </tr>
        <tr>
            <th>D</th>
            <td id="i2j0">sc</td>
            <td  id="i2j1">sc</td>
            <td id="i2j2">sc</td>
            <td></td>
        </tr>
    </tbody>
</table>

如果所需的对是列标题“ B”和单元格“ sa”,则应返回ID为i0j1的td。 如果该对是列标题“ B”和单元格“ sb”,则应返回ID为i1j1元素。

之前我在提出这个问题时遇到问题,目前还不清楚。 如果您需要更多信息,请与我们联系。 可在此处找到具有其表示形式的JSBin: http : //jsbin.com/amowUBA/7/edit

我最终遇到了这种情况:

  _parameter = 'B';
  _state = 'sa';  

  // columns are in the first row
  var column = $('tr:eq(0) > th:contains("'+_parameter+'")');
  var cell = $('td:nth-child('+parseInt(column.index()+1)+'):contains("'+_state+'")');

要查看其实现,请检查以下内容: http : //jsbin.com/amowUBA/9/edit

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM