- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个 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/
我已被选中一行,现在我想获取 rowIndex 也许喜欢 grid.getSelectionModel().getSelection()[0].rowIndex 但它是未定义的。我怎样才能得到它谢谢
我的 Button1 在面板内,我想访问 rowindex 以便隐藏该 Imagebutton。但是当我进入 Debug模式时,GridView1.SelectedIndex 有一个空值。请帮忙!
我有如下代码。我的问题是我无法获取页脚的行索引。使用代码,我得到了页脚的 rowindex = -1。我试图在网上找到解决方案,但没有找到任何东西。感谢您帮助我。先感谢您。 protected v
有没有办法让每个人都得到行索引? 示例: int rowIndex = 0; foreach (int a in numbers) { // Manipulation rowIndex
我正在使用 TR 的 rowIndex 属性,但它不起作用。如果我在这里做错了什么,请告诉我。 function myMethod(){ alert ( this.pa
单击时我的表格单元格会突出显示。我需要找到突出显示的单元格的 rowIndex 。我尝试这样做 $(".ui-state-highlight").index(); // Results to 0 我也
我有一个简单的 GridView 。每行都有一些 boundFields 和一个复选框。该复选框具有 AutoPostBack=True 并使用 OnCheckedChanged 事件触发方法 (ch
我正在使用 greasemonkey 脚本并使用以下代码更新表格。我附上了 table 的图片。但是当我点击 delete 时,rowIndex 为所有行返回 -1。我不明白为什么它返回 -1。 ta
我是新手,我想通过 onclick 获取行索引、colindex 和该行第一列的值。我在不同的部分找到了这些答案,但无法将它们放在一起。如果下面的代码也能为我提供第一列中的值,我将非常高兴。提前致谢。
下面是我写的代码来做以下事情 每个表格行都包含一个“+”按钮 当点击按钮时,代码应该找到被点击行的行索引 然后一个新行应该添加到 cilcked 行的 (rowindex+1) 位置。即,就在点击行的
... 存在一些这样的 ... 对于数据表 最佳答案 在您用于扩展行的 ng-template 中使用以下代码 expand 在展开时点击的按钮使用下面的代码获取行索引 expand(
我有一个带有 DataGridTemplateColumns 的 DataGrid。在 TemplateColumn 中,我使用了一个工作正常的 DataTrigger。它从 DataGrid 父级检
如果我在 VBA 编辑器中编写此内容: Dim ws As Worksheet: set ws = ActiveSheet ws.Columns( IntelliSense 向我显示了一个看似不相关的
我尝试获取表中按钮的 rowIndex?没有什么对我有用: let tr = $(''); let td = $(''); let btn = $(''); td.html(btn); tr.html
这可能是非常规的,但我想知道如何编辑表行的索引? 所以我可以像这样获取表行的当前 rowIndex var rowIndex = document.getElementsByClassName('ed
我试图将行索引从 gridview 内部传递到 javascript 函数,但收到错误消息,指出 databind 不包含属性名称容器。 ','','','',');"> 我只想将 gridview
我的 GridPanel 中有一堆来自一家商店的 RowIndexes。我想从我的商店中删除这些。如果我只有一个,没问题,Grid 的 View 是 refrsehd,唯一的条目是 away。 但是当
我试图找到具有被单击的删除按钮的行的 rowIndex。但是,当单击删除按钮时,它找不到 ID,而是返回 null 并出错。 我试过这个: $("#delete").on("click", funct
我需要小部件列中的一个按钮来了解其在 ExtJS 6 panel.grid 中的 rowIndex,以便在单击按钮时它可以使用该功能。我知道我可以从渲染器函数中提取该信息,但这似乎是在创建按钮之前执行
您好,我正在开发一个使用 block 的 2d map 加载器。 我使用此方法来计算与屏幕边界相交的 block 的位置。 // left bottom rect.x = x - x % chunkS
我是一名优秀的程序员,十分优秀!