具有先前rowspan列的表列索引 [英] Table column index with previous rowspan columns

查看:125
本文介绍了具有先前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 =).

这篇关于具有先前rowspan列的表列索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆