代码之家  ›  专栏  ›  技术社区  ›  Scott Baker

FireFox/JQuery/Dom:不返回“rowIndex”

  •  1
  • Scott Baker  · 技术社区  · 15 年前

    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 alert($rowSpanningCell.parent('tr').get(0).nodeName) 我得到了预期的结果 <TR> ,所以我知道我的选择是正确的。该行的每个其他属性的每个其他值似乎都返回罚款-但是 行索引

    1 回复  |  直到 13 年前
        1
  •  1
  •   redsquare    15 年前

    你可以试试

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