Javascript 在应用appendto之后,将表代码的最后一个td更改为新代码

Javascript 在应用appendto之后,将表代码的最后一个td更改为新代码,javascript,jquery,html-table,append,Javascript,Jquery,Html Table,Append,基本上,我的代码是关于单击add按钮并将行从table2(id=second)移动到table1(id=first) 我的问题 这是我代码中的最后一个td <a href="#/" class="plusicon"><i class="fa fa-plus-circle"></i></a> 1. 第一值 2. 第二值 3. 第三值 1. 第一值 您应该尝试将#first表的td:last child替换为newLinkText $(row

基本上,我的代码是关于单击add按钮并将行从table2(id=second)移动到table1(id=first)

我的问题

这是我代码中的最后一个td

<a href="#/" class="plusicon"><i class="fa fa-plus-circle"></i></a>

1.
第一值
2.
第二值
3.
第三值

1. 第一值


您应该尝试将
#first
表的
td:last child
替换为
newLinkText

$(row).appendTo(targetTable).addClass("tablerow").find("td:last-child").html(newLinkText);
这是您更新的javascript

$(function() {
   function moveRow(row, targetTable, newLinkText){
       $(row).appendTo(targetTable).addClass("tablerow").find("td:last-child").html(newLinkText);
   }

   $("#second a").on("click", function(){
       moveRow($(this).parents("tr"), $("#first"), "<p><a href='#'><i class='fa fa-search lightgreytxt txt14'></i></a></p><p><a href='#/' class='minusicon removerow'><i class='fa fa-minus-circle'></i></a></p>");
   });

   $('#first').on('click', '.removerow', function() {
     $(this).closest('tr').remove()
   });
});
$(函数(){
函数moveRow(row、targetTable、newLinkText){
$(行).appendTo(targetTable).addClass(“tablerow”).find(“td:last child”).html(newLinkText);
}
$(“#秒a”)。在(“单击”,函数(){
moveRow($(this).parents($),$(“#first”),“”;
});
$('#first')。在('单击','.removerow',函数()上{
$(this).closest('tr').remove()
});
});

希望这有帮助。

您应该尝试用
newLinkText
替换
#first
表的
td:last child

$(row).appendTo(targetTable).addClass("tablerow").find("td:last-child").html(newLinkText);
这是您更新的javascript

$(function() {
   function moveRow(row, targetTable, newLinkText){
       $(row).appendTo(targetTable).addClass("tablerow").find("td:last-child").html(newLinkText);
   }

   $("#second a").on("click", function(){
       moveRow($(this).parents("tr"), $("#first"), "<p><a href='#'><i class='fa fa-search lightgreytxt txt14'></i></a></p><p><a href='#/' class='minusicon removerow'><i class='fa fa-minus-circle'></i></a></p>");
   });

   $('#first').on('click', '.removerow', function() {
     $(this).closest('tr').remove()
   });
});
$(函数(){
函数moveRow(row、targetTable、newLinkText){
$(行).appendTo(targetTable).addClass(“tablerow”).find(“td:last child”).html(newLinkText);
}
$(“#秒a”)。在(“单击”,函数(){
moveRow($(this).parents($),$(“#first”),“”;
});
$('#first')。在('单击','.removerow',函数()上{
$(this).closest('tr').remove()
});
});

希望这有帮助。

更新了我的删除代码。它无法工作,因为该行是动态添加的。检查这个简短的解释。我改成了这个
$(“#first”).delegate(“a.removeow”,“click”,function(){}),它也能工作!更新了我的删除代码。它无法工作,因为该行是动态添加的。检查这个简短的解释。我改成了这个
$(“#first”).delegate(“a.removeow”,“click”,function(){}),它也能工作!