次の表を検討してください。
<table>
<thead>
<tr>
<th scope="col" />
<th scope="col">A</th>
<th scope="col">B</th>
<th scope="col">C</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Apples</td>
<td>Oranges</td>
<td>Pears</td>
</tr>
<tr>
<th scope="row">2</th>
<td rowspan="2">Subcategory Heading</td>
<td>ASP.Net</td>
<td>Other</td>
</tr>
<tr>
<th scope="row">3</th>
<td>MVC</td>
<td>PHP</td>
</tr>
<tr>
<th scope="row">4</th>
<td>Red</td>
<td>Green</td>
<td>Blue</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">Some pointless footer content</td>
</tr>
</tfoot>
</table>
jQueryを使用して、テキスト「MVC」または「PHP」を含むセルの正しい列番号を取得するにはどうすればよいですか? 正解は列 3 ですが、使用.prevAll().length
するだけでは前のセルの数だけがカウントされるため、この場合、実際の列の位置が正確に反映されませんか?
を使用する必要があると確信していますがeach()
、最も効率的な実装も探しています。