I have a large table, and I need to be able to select a specific cell using it's cell/row coordinates.
What's the most elegant way of doing t开发者_如何学编程his using jQuery?
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.
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 */
Here's an example: http://jsfiddle.net/CgqQt/
After reviewing the fiddle you posted in one of your comments, this could also work.
http://jsfiddle.net/CGrP9/6/
$('tbody tr').eq(2).find('td').eq(2).css('background-color', 'green');
I'm pretty sure this selects the cell at coordinate (9, 9)
. Let me test:
$('table tr:eq(10) > td:eq(10)')
$($("table#wall_layout tr")[row]).find("td")[col]
精彩评论