2011-09-17 108 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,它們非常有用。