点击表1的'td'后,我将该行的一些单元格附加到另一个表格(表格2),而不移动/更改表格1中的那一行。
现在为了避免重复,我将表添加到表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');
}):
现在,当我试图从table2中删除附加的行时...我必须删除类'done' 这是我添加到table1的clided'td'。
怎么做?有没有其他方法可以做到这一点(避免重复)除了添加类??
这是fiddle。
请帮助。 感谢
答案 0 :(得分: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}
}
});
});