2011-09-17 155 views
1

我有结构性10行如下表:帮助jQuery选择

<table> 
    <tr id='row1'> 
     <td> 
      <input id='input1' type='text' class='data'> 
     </td> 
    </tr> 
    <tr id='row2' class='hide'> 
     <td> 
      <input id='input2' type='text' class='data'> 
     </td> 
    </tr> 
    <tr id='row3' class='hide'> 
     <td> 
      <input id='input3' type='text' class='data'> 
     </td> 
    </tr> 
    . 
    . 
    . 
    (down to 10 rows) 
</table> 

我需要做的是当值“输入(X)”更改为“作秀”“行(X + 1)”。我一直在试图弄清楚如何“回到”输入字段的父“tr”,然后以某种方式获得下一行的“tr”,但我没有取得太大的成功。

我的 '隐藏' 类如下:

谢谢!

回答

2

使用closest("tr")向上导航到包含其值的输入表行发生了变化,那么next获得下一行,最后表现出来:

$("input.data").change(function() { 
    $(this).closest('tr').next().show(); 
}); 

你可能想看看所有tree traversal methods,它们非常有用。