2013-06-04 161 views
-1

我是初學者,僅瞭解javascript和MVC的基礎知識。現在我需要每當行選中從所附的表中刪除相應的行.. 這是我的表...未選中複選框時,從附加表中刪除行

<table id="sortabletable" class="tab sortable"> 

    <tr class = trow> 
      <td> 
       @Html.DisplayFor(modelItem => item.AId) 
      </td> 
      <td>     
       @Html.DisplayFor(modelItem => item.UId) 
      </td> 

      <td><input type="checkbox" name="thecheckbox" value="@item.TXId" class ="cbox" checked/></td> 
     </tr> 
</table> 
<table class="tab" id="tlist"> 
<tbody> 
</tbody> 
</table> 

,這裏是我的jQuery的

$(function() { 
    $('input[type="checkbox"]').click(function() { 
     _this = $(this); 
     if ($(this).is(':checked')) { 
      row.find('td:nth-child(1), td:nth-child(3)').hide(); 
      var row = _this.closest("tr").clone(); 
      $('#tlist').append(row); 
     } else { 
      // i dont know 
     } 
    }); 
}); 

我不知道如何根據附加表中的選中值選擇行。

回答

1

使用closestremove

$('input.cbox').on('change', function() { 
     var _this = $(this); 
     if(this.checked) { 
     var row = _this.closest("tr").clone(); 
     row.find('td:nth-child(1), td:nth-child(3)').hide(); 

     row.data('id' , this.value); 
     $('#tlist').append(row); 
     } 
     else { 
      $('[data-id="'+ this.id +'"]', '#tlist').remove() 
     } 
}); 
+0

的組合,但它會從我的檢查表中刪除的行...我需要從表#tlist,附加一個將其刪除。 – JRU

+1

我不認爲你的問題是明確的。你可以粘貼部分呈現的HTML和你期待的內容 –

+0

我試圖從複選框的另一個表中創建一個新的表#tlist。所以當我檢查時,整行將自動添加到新表中並且它工作正常。同樣,當我取消選中時,必須從新表#tlist中刪除該特定行。 – JRU

相關問題