2017-06-18 13 views
0

私はJSFiddleで述べたようなテーブルを持っています。 私は最初から灰色部分を隠したいと思います。ユーザーが「詳細を表示」をクリックすると、スパンテキストが変更され、グレーの部分が表示されます。逆に、ユーザーが「詳細を表示」を再度クリックすると、スパンテキストが元の形状に戻り、灰色の部分が非表示になります。jQuery onclickの変更スパンのテキストを変更し、隠しテーブルを表示

私はそれに対処するためにいくつかのjQueryを書こうとしましたが、なぜ動作していないのかわかりません。灰色の部分も表示することはできません...誰もそれについての提案はありますか? @Dineshの提案に基づいて

$('.view-detail').on('click',function(){ 
    $('#table1 tr.show-history').css({"display":"block"}); 
    $(this).find('.right').text("▼"); 
}); 

Editted: はトグル機能は、それがすべてのクリックでトグルになります...私は変更される可能性がどのようにそのようなことをクリックするために一度働いていましたか?

$('.view-detail').click(function(){ 
    $('.show-history').toggle(function(){ 
     $('#table1 tr.show-history').css({"display":"block"}); 
     $(this).find('.right').html("▼"); 
    }, function(){ 
     $('#table1 tr.show-history').css({"display":"none"}); 
     $(this).find('.right').html("►"); 
     }); 
    }); 

答えて

1

あなたはjqueryのをロードし$(this).find('.right').html("▼");代わり$(this).find('.right').text("▼");

var flag = false; 
 
$('.view-detail').on('click',function(){ 
 
\t $('#table1 tr.show-history').toggle(); 
 
    if(flag == false){ 
 
    $(this).find('.right').html("▼"); 
 
    flag = true; 
 
    }else{ 
 
    $(this).find('.right').html("►"); 
 
    flag = false; 
 
    } 
 
});
#table1{ 
 
    background-color:white; 
 
    width:500px; 
 
} 
 
.item-history{ 
 
    width:80%; 
 
    margin:0 auto; 
 
    background-color:#ebebeb; 
 
} 
 

 
.show-history{ 
 
    display:none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<table id="table1"> 
 
<tr class="view-detail"> 
 
    <td> 
 
    <span class="right">&#9658;</span> View Detail 
 
    </td> 
 
</tr> 
 
<tr class="show-history"> 
 
<td> 
 
<div class="item-history"> 
 
<table> 
 
<tr><td>Row 1 History</td></tr> 
 
<tr><td>Row 2 History</td></tr> 
 
<tr><td>Row 3 History</td></tr> 
 
</table> 
 
</div> 
 
</td> 
 
</tr> 
 
<tr> 
 
    <td>Item 1 Description.........................................................................</td> 
 
</tr> 
 
<tr> 
 
<td>Total: 1 Item</td> 
 
</tr> 
 
</table>

+0

こんにちはディネッシュを使用していませんが、ご提案をいただき、ありがとうございます。私はあなたのコメントで何かを調整した後、自分の投稿を更新しました。私が隠すことができ、灰色のクリックを表示することができるすべてのクリックでどのように切り替えることができるか知っていますか?現在、私のスクリプトのためには一度だけ表示することができます... – Sammi

+0

@Samiは今私のコードをチェックします。私は今更新しました –

+0

今はうまくいっています!ありがとう@Dinesh !!! – Sammi

関連する問題