私は提供された答えを使用していました:
jQueryを使用して各テーブルセルの「視覚的な場所」を見つけるにはどうすればよいですか?
しかし、この場合はうまくいかないようです: http://jsfiddle.net/TRr6C/9/
1,3 1,4 と 2,4 は 1,4 1,5 と 2,5 でなければならないことに注意してください
誰が何が悪いのか分かりますか?
または、colspan と rowspan を考慮して、テーブル セルから cellIndex と rowIndex を取得するためのより良い解決策はありますか?
コードは次のとおりです。
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 = row.children("td").index($(this));
//check if this cell comes before our cell
if (cell.offset().left > $(this).offset().left) {
// check if it has both rowspan and colspan, because the single ones are handled before
var colspn = parseInt($(this).attr("colspan"));
var rowspn = parseInt($(this).attr("rowspan"));
if (colspn && rowspn) {
if(rowindex + rowspn > rows)
cols += colspn;
}
}
});
});
return {
rows: rows,
cols: cols
};
}