2015-09-28 37 views
0

我的表中有两行,如此jsfiddle链接所示, http://jsfiddle.net/o6ew3zom/使用next()选择下一个表格行给出undefined

我选择使用table tr所有行和访问下一行作为,

$(this).next() 

它打印,

the current element id is firstRow 
the next element id is undefined 
the current element id is secondRow 
the next element id is undefined 

我预计,

the current element id is firstRow 
    the next element id is secondRow 
    the current element id is secondRow 
    the next element id is undefined 
+0

东阳这不是它的兄弟姐妹,一个是内部THEAD和其他内部TBODY –

+0

它的作品,感谢所有.. –

回答

1

因为一个是在THEAD另一个在tbody中。 thead中没有下一个元素,tbody中没有下一个元素。但是,如果您尝试删除thead和tbody,它将显示第一个的下一个元素的id,如小提琴中所示。

demo

<table> 
    <tr id="firstRow"> 
     <th>state</th> 
     <th>compound</th> 
    </tr> 
    <tr id="secondRow"> 
     <td>solid</td> 
     <td>iron</td> 
    </tr> 
</table> 
1
JQuery.next()

函数返回下一个同级元件

如果你需要得到所有行表使用此:

var allrows = $(this).closest("table").find("tr"); 
相关问题