从td获取列号

时间:2011-02-15 13:20:29

标签: javascript jquery tablesorter

tablesorter 编写扩展程序..虽然这是我第一次尝试扩展任何js。我在<select> s&amp;行中有<td>$('select').change(function(){ }); 个。需要知道这个td所在的列。

当在任何这些选择中更改值时,例如

col

我需要抓住此选项的列,以便为('tr.result > td:nth-child('+col+')').each(function(){ 设置:

$('select').change(function(){

    td  = $(this).parent('td');

    col = $(td).parent().children().index(td);

});

有没有办法可以从td选择中得到这个?!?

- 解决我的具体问题是:

{{1}}

2 个答案:

答案 0 :(得分:8)

您可以使用index()功能。

col = $(this).parent().children().index($(this));

答案 1 :(得分:5)

  

cellIndex属性返回表格行的单元格集合中单元格的位置。   w3schools

 td.cellIndex 

demo

相关问题