Javascript FireFox/JQuery/Dom:不返回';行索引

Javascript FireFox/JQuery/Dom:不返回';行索引,javascript,jquery,firefox,dom,Javascript,Jquery,Firefox,Dom,我正在编写一个JavaScript函数来突出显示单击单元格的行和列。此函数必须考虑前几行中使用rowspan向下突出到选定行中的单元格,因为这会导致单元格索引与“明显”索引不同。也就是说,表格第二列中的每个单元格不一定都有cellIndex==1 为了补偿,我编写了以下函数来计算每个受影响单元的“偏移” function OffsetCells($tbody) { // if already indexed, we don't need to re-do it if (!$tbody.data(

我正在编写一个JavaScript函数来突出显示单击单元格的行和列。此函数必须考虑前几行中使用
rowspan
向下突出到选定行中的单元格,因为这会导致单元格索引与“明显”索引不同。也就是说,表格第二列中的每个单元格不一定都有
cellIndex==1

为了补偿,我编写了以下函数来计算每个受影响单元的“偏移”

function OffsetCells($tbody) {
// if already indexed, we don't need to re-do it
if (!$tbody.data('isOffset').value) {
    // set offset for all cells to zero
    $tbody.find('td').data('offset', { value: 0 });
    // it's not already indexed, so get the cells that span multiple rows
    // capitalization of 'rowSpan' is important for IE
    var $rowSpanners = $tbody.find('td[rowSpan!=1]');
    $rowSpanners.each(function() {
        var $rowSpanningCell = $(this);
        // we need to select all the cells to the 'apparent' right of this cell, 
        // so we need this cell's apparent position
        // multiplying by one is easier than parseInt() to ensure conversion
        $rowSpanningCell.data('apparentIndex', { value: this.cellIndex * 1 +     $rowSpanningCell.data('offset').value });
        // we also need to know what row this cell is in 
/*???*/     $rowSpanningCell.data('rowIndex', { value: $rowSpanningCell.parent('tr').get(0).rowIndex });
        // down to business:
        $tbody.parent('table')  // get the whole table
        .find('tr')            // get all the rows in the table
        .slice($rowSpanningCell.data('rowIndex').value + 1, $rowSpanningCell.data('rowIndex').value + this.rowSpan) // narrow selection to the applicable rows
        .find('td')             // get the cells in the chosen rows
        .filter(function(index) {  // get the cells to the apparent right of this one.
            return index + $(this).data('offset').value >= $rowSpanningCell.data('apparentIndex').value;
        }).each(function() {
            $(this).data('offset', { value: $(this).data('offset').value + 1 });
        });
    });
    $tbody.data('isOffset', { value: true });
}
}
这段代码在IE中工作得非常好,但在
/*?*/
行中以静默方式失败。我已经把它缩小到
$rowSpanningCell.parent('tr').get(0).rowIndex
部分。我已经尝试了我能想到的一切,但仍然无法让它返回
rowIndex
值。当我将代码更改为
警报($rowSpanningCell.parent('tr').get(0.nodeName)
时,我得到了预期的
,因此我知道我的选择是正确的。行的每个其他属性的每个其他值似乎都返回良好-但是
rowIndex
只是停止代码冷启动。

您可以尝试

$rowSpanningCell.parent('tr').prevAll().length

这将为您提供索引,您可以尝试

$rowSpanningCell.parent('tr').prevAll().length


这将为您提供索引

解决我发现的问题的另一种方法是使用$rowSpanningCell.parent()[0]。sectionRowIndex。SectionRowIndex是受支持的,并且在这两种情况下都起作用。解决我发现的问题的另一种方法是使用$rowSpanningCell.parent()[0]。SectionRowIndex。SectionRowIndex是受支持的,并且可以在这两种情况下工作。