2 つのテーブル間で行を移動しようとしていますが、クリック イベントをバインドしたままにすることができません。イベントのセレクター部分で混乱して.on
います。それで何をターゲットにしているのかわかりません。
基本的に、1 つのテーブルに移動して元に戻すことはできますが、クリック プロパティが失われます。理由がわからない。
問題をより明確にするために、フィドル(http://jsfiddle.net/Yjqkn/216/ )を添付しました。承認ボタンで下に移動し、待機リスト ボタンで元に戻しますが、すべてのイベント リスナーが失われます.bind
。
試した:.on("click","button.remove-participant",function()
うまくいかなかった
Javascript
$( ":button" ).on("click",function(){
if($(this).hasClass('remove-participant')) {
$(this).removeClass('remove-participant').addClass('add-participant');
$(this).html('Approve');
var current_row = $(this).closest('tr').html();
$('.table_2 > tbody:last').append('<tr>'+current_row+'</tr>');
$(this).closest('tr').remove();
$( ".table_2 .add-participant" ).bind( "click", function() {
$(this).removeClass('add-participant').addClass('remove-participant');
var current_row = $(this).closest('tr').html();
$(this).html('Waitlist');
$('.table_1 > tbody:last').append('<tr>'+current_row+'</tr>');
$(this).closest('tr').remove();
});
}
});
HTML
<table class="table_1">
<tr>
<th>Info Header 1</th><th>Info Header 2</th>
</tr>
<tbody>
<tr><td>Don</td>
<td><button class="remove-participant" name="">Remove</button></td>
</tr>
</tbody>
</table>
<table class="table_2">
<tr>
<th>Info Header 1</th><th>Info Header 2</th>
</tr>
<tbody>
<tr></tr>
</tbody>
</table>