使用 jQuery 通过索引获取 td [英] Getting td by index with jQuery
本文介绍了使用 jQuery 通过索引获取 td的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何使用 jQuery 获取单元格的行和列索引,但我无法弄清楚相反的情况.给定行和列索引,我将如何访问此位置的 td?
I know how to get a cell's row and column index with jQuery, but I can't figure out the reverse. Given a row and column index, how would I access the td at this location?
推荐答案
使用纯 JavaScript:
With plain JavaScript:
// table is a reference to your table
table.rows[rowIndex].cells[columnIndex]
参考: HTMLTableElement
, HTMLTableRowElement
使用 jQuery,您可以使用 .eq()
:
With jQuery, you could use .eq()
:
$('#table tr').eq(rowIndex).find('td').eq(columnIndex)
// or
$('#table tr:eq(' + rowIndex + ') td:eq(' + columnIndex + ')')
这篇关于使用 jQuery 通过索引获取 td的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文