2012-01-14 78 views
-1

我有以下結構問題與jQuery

<table> 
    <tr> 
     <td><img class='show_detail'></td> 
    <tr> 
    <tr class='detail'> 
     <td>XYZ</td> 
    <tr> 

    <tr> 
     <td><img class='show_detail'></td> 
    <tr> 
    <tr class='detail'> 
     <td>ABC</td> 
    <tr> 

    </table> 

我想如果類show_detail點擊於明年明細行應顯示和隱藏所有打開的TR與類細節意味着,如果首秀細節類被點擊超過它隱藏第二個細節類並顯示第一個細節類。

我嘗試jQuery的這個

$('.show_detail').click(function() { 
    $('.show_detail').next('.detail').slideDown(); 
}); 

回答

2

試試這個

$('.show_detail').click(function() { 
    var elem = $(this).parents('tr').next('.detail'); // get the next tr with class detail 
    $('.detail').not(elem).hide(); // hide all the tr with detail class excluding the next. 
    elem.toggle(); // toggle(hide <-> show) the next tr with detail class. 
}); 
+0

我怎樣才能使它彷彿相同show_detail點擊任何細節類的開放比封閉開放的.. – 2012-01-14 17:18:38

+0

而不是顯示使用切換所有。更新了答案。 – 2012-01-14 17:23:21

+0

我不是jquery的高手......你能解釋一下3和4步嗎? – 2012-01-14 17:29:55