我有一个大表,我需要能够使用它的单元格/行坐标选择一个特定的单元格.
使用jQuery执行此操作的最优雅方法是什么?
我正在使用以下提供的答案:
但它似乎在这种情况下不起作用:http://jsfiddle.net/TRr6C/9/
请注意,1,3 1,4和2,4应为1,4 1,5和2,5
有人看到什么错了吗?
或者有没有更好的解决方案从表格单元格中获取cellIndex和rowIndex考虑colspan和rowspan?
这是代码:
function getCellLocation(cell) {
var cols = cell.closest("tr").children("td").index(cell);
var rows = cell.closest("tbody").children("tr").index(cell.closest("tr"));
var coltemp = cols;
var rowtemp = rows;
cell.prevAll("td").each(function() {
cols += ($(this).attr("colspan")) ? parseInt($(this).attr("colspan")) - 1 : 0;
});
cell.parent("tr").prevAll("tr").each(function() {
//get row index for search cells
var rowindex = cell.closest("tbody").children("tr").index($(this));
// assign the row to a variable for later use
var row = $(this);
row.children("td").each(function() {
// fetch all cells of this row
var colindex …Run Code Online (Sandbox Code Playgroud)