按行号和列号选择表格中的任意单元格 [英] Selecting an arbitrary cell in a table by row and column number
本文介绍了按行号和列号选择表格中的任意单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很大的表格,我需要能够使用它的单元格/行坐标来选择一个特定的单元格.
I have a large table, and I need to be able to select a specific cell using it's cell/row coordinates.
使用 jQuery 执行此操作最优雅的方法是什么?
What's the most elegant way of doing this using jQuery?
推荐答案
这是我认为使用原生 JavaScript 实际上使代码更易于理解的一种情况:
This is one case where I think using native JavaScript actually makes the code easier to understand:
var table = $("#table")[0];
var cell = table.rows[1].cells[1]; // This is a DOM "TD" element
var $cell = $(cell); // Now it's a jQuery object.
请注意,只需选择 table
元素将使 rows
包含在您的 thead
(和 tfoot
).你可能想要的是:
Note that just selecting the table
element will make rows
include those rows in your thead
(and tfoot
). What you probably want is:
var table = $("#table tbody")[0];
/* remaining code from above */
这是一个例子:http://jsfiddle.net/CgqQt/
这篇关于按行号和列号选择表格中的任意单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文