簡體   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