2013-10-16 45 views
0

在點擊表1的'td'後,我將該行的一些單元格追加到另一個表(表2),而無需從表1移動/更改該行。如何避免選擇重複的html行克隆使用jquery

我們避免我從表1 類添加到「TD」像這種

$(".table1 td:first-child + td").click(function(){ 

    $("#table2").append('<tr><td>clicked TD value from table 1</td> more td's</tr>'); 
    $(this).addClass('done'); 
}): 

現在,當我試圖從表2刪除附加行重複......我不得不刪除班'完成' 這是我添加到表1的cliked'td'。

如何做到這一點??除了添加類以外,是否還有其他方法可以做到這一點(避免重複)?

這是fiddle

請幫忙。 感謝

+0

能否請您帶來更多的信息有着深刻的修訂?一個[fiddle](http://jsfiddle.net/)可能會有用,看看你正在嘗試做什麼,並得到所有約束';)' – Stphane

+0

而不是你必須傳遞一個獨特的東西像行done1,所以同時刪除table2行,你可以得到它對應的表1 –

+0

@ f00bar的行,只是在帖子中添加小提琴。 – HungryDB

回答

1

這裏是你的代碼

小提琴HERE

$(function() { 
    $("#selections tbody").on('click', function (e) { 
     var $td = $(e.target); 
     if ($td.prevAll('td').length === 1) { 
       var $destiny = $('#destiny'), 
           // Any row in destiny that would be a clone of the current clicked td's row 
      // You may want to put an id to make sure it is uniq 
       $trDestiny = $('tr[rel="' + $td.text() + '"]', $destiny); 
       // ... 
      if (!$trDestiny.length) { 
       // Insert new row ... 
      } 
      // else {error handling here} 
     } 
    }); 
}); 
+0

這正是我想要的...謝謝.. – HungryDB

+0

http://jsfiddle.net/KPe9T/6/我更新了小提琴,我無法理解一些代碼...你會詳細說明嗎? – HungryDB

+0

當然,我可以!現在檢查[第8版](http://jsfiddle.net/KPe9T/8/)...順便說一下,請將答案設置爲考慮我的工作的解決方案';)' – Stphane