gpt4 book ai didi

javascript - FireFox/JQuery/Dom : Not returning 'rowIndex

转载 作者:行者123 更新时间:2023-11-28 03:00:03 25 4
gpt4 key购买 nike

我正在编写一个 JavaScript 函数来突出显示单击的单元格的行和列。此函数必须考虑前一行中使用 rowspan 的单元格向下突出到所选行 - 因为这会导致单元格索引与“表观”索引不同。 IE。表格第二列中的每个单元格不一定都有 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值(value)。当我将代码更改为alert($rowSpanningCell.parent('tr').get(0).nodeName)时我得到了预期的 <TR> ,所以我知道我的选择是正确的。该行的每个其他属性的每个其他值似乎都返回正常 - 但是 rowIndex只是停止代码。

最佳答案

你可以试试

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

这将为您提供索引

关于javascript - FireFox/JQuery/Dom : Not returning 'rowIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1369321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com