javascript 从 td 获取列号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5004146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting column number from td
提问by null
Writing an extension for tablesorter.. though its my first attempt at extending any js. I have a number of <select>s within a row of <td>s & need to know the column this td sits in.
为tablesorter编写扩展......尽管这是我第一次尝试扩展任何 js。我在<select>s 的一行中有多个s 并且<td>需要知道这个 td 所在的列。
When a value is changed in any of these selects e.g.
当这些选择中的任何一个中的值发生更改时,例如
$('select').change(function(){
});
I need to get hold of the column this select is sittingin to set colfor:
我需要得到这个选择是列保持坐在中设置col为:
('tr.result > td:nth-child('+col+')').each(function(){
Is there a way I can get this from the td select is in?!?
有没有办法可以从 td select 中得到这个?!?
-- solution for my specific problem was:
- 我的具体问题的解决方案是:
$('select').change(function(){
td = $(this).parent('td');
col = $(td).parent().children().index(td);
});
采纳答案by ReFocus
You can use the index()function.
您可以使用该index()功能。
col = $(this).parent().children().index($(this));

