2016-02-09 29 views
0

我想打開第一個<tr>單擊時另一個<tr>標記。 的代碼是:打開msg td單擊滑動並滑動的事件

<tr class="msg_inner"> 
    <td><label>some text</label></td> 
    <tr id="full_msg" style="display:none"> 
     <td><label>Hey There.....</label></td> 
    </tr> 
</tr> 

腳本

$('.msg_inner').click(function(){ 
     $('#full_msg_'+no+'').toggle("slow"); 
}); 

它顯示塊,但都在同一時間打開。我想在點擊<tr>之後顯示該塊。

+2

''元素不能是其他''元素的直接子元素。 –

+0

'$(this).next()。toggle(「slow」);' –

回答

1

請勿使用其他<tr>。 只需添加一個<div>在TD,只是表明他那個樣子

HTML:

<table> 
<tr class="line"> 
<td> 
    Hi there !! 
    <div class="detail"> 
    More info here... 
    </div> 
    </td> 
</tr> 
<tr class="line"> 
<td> 
    Hi there ! 
    <div class="detail"> 
    More info here... 
    </div> 
    </td> 
</tr> 
<tr class="line"> 
<td> 
    Hi there ! 
    <div class="detail"> 
    More info here... 
    </div> 
    </td> 
</tr> 
</table> 

CSS

.detail{ 
    display:none; 
} 

JQuery的

$(".line").click(function(){ 
$(this).find(".detail").toggle(); 
}); 

Working Fiddle here

0

你可以試試這個:

var x=0; 
$(".line").click(function(){ 

if((x%2)==0) 
{ 
$(this).find(".detail").show(); 
} 
else 
{ 
    $(this).find(".detail").hide(); 
} 
x++; 
}); 

DEMO HERE

或者

的toogle方法

$(".line").click(function(){ 
$(this).find(".detail").toggle(1000); 
}); 

DEMO HERE

+0

爲什麼當你可以使用切換? – Alexis