具有先前rowspan列的表列索引
我有以下jsfiddle准备向您展示我的问题
I have the following jsfiddle ready to show you my problem
`https://jsfiddle.net/rwurzer/no4sefyu/`
基本上我遇到的问题是一个表格列,其中我指定了rowspan。
Basically the problem I have is a table column where I have rowspan assigned to.
我想获得正确的列索引。
I want to get the right column index.
我希望我的小提琴足以解释我的问题: - )
I hope my fiddle is good enough to explain my problem :-)
希望有人可以提供帮助吗? / p>
Hope anyone can help?
嗯,我知道你已经通过尝试这个变种得到了答案。它基于计算索引,应该适用于任何单元格。我在jsFiddle中删除了重复的 id
属性。
Well, I know that you've already got an answer by try this variant. It's based on calculating indexes and should work for any cell. And I've removed duplicate id
attributes in jsFiddle.
$('td').click(function(){
var clickedEl = $(this);
var myCol = clickedEl.closest("td").index();
var myRow = clickedEl.closest("tr").index();
var rowspans = $("td[rowspan]");
rowspans.each(function () {
var rs = $(this);
var rsIndex = rs.closest("tr").index();
var rsQuantity = parseInt(rs.attr("rowspan"));
if (myRow > rsIndex && myRow <= rsIndex + rsQuantity - 1) {
myCol++;
}
});
alert('Row: ' + myRow + ', Column: ' + myCol);
});
这是 jsFiddle 。只想用这种方法解决你的问题=)。
Here is a demo in jsFiddle. Just want to solve your problem with this approach =).