Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用JQuery选择命名HTML表中的第一行进行克隆_Jquery_Html Table_Row_Cloning - Fatal编程技术网

使用JQuery选择命名HTML表中的第一行进行克隆

使用JQuery选择命名HTML表中的第一行进行克隆,jquery,html-table,row,cloning,Jquery,Html Table,Row,Cloning,要复制特定命名表中的第一行或最后一行。我有大量的专栏,因此克隆是最好的方法 我的问题是,在哪里更改选择器以指定我要查找的表?如果您注意到添加行只会添加到一个表中,但它似乎是从第一个可用表中克隆行。假设我只想复制表1中的行,因为我要附加到表1。如何执行此操作?更新了定义了从表1到表2的代码示例 var i = 1; $("button").click(function() ​​​{ $("table#table1 tr:first").clone().find("input").each(fu

要复制特定命名表中的第一行或最后一行。我有大量的专栏,因此克隆是最好的方法


我的问题是,在哪里更改选择器以指定我要查找的表?如果您注意到添加行只会添加到一个表中,但它似乎是从第一个可用表中克隆行。假设我只想复制表1中的行,因为我要附加到表1。如何执行此操作?

更新了定义了从表1到表2的代码示例

var i = 1;
$("button").click(function() ​​​{
  $("table#table1 tr:first").clone().find("input").each(function() {
    $(this).val('').attr('id', function(_, id) { return id + i });
  }).end().appendTo("table#table2");
  i++;
})​;​
试试这个:

为id为table 1的表追加行:

$("button").click(function() ​​​{
  $("#table1 tr:first").clone().find("input").each(function() {
    $(this).val('').attr('id', function(_, id) { return id + i });
  }).end().appendTo("#table1");
  i++;
})​;​
为id为table 2的表追加行:

$("button").click(function() ​​​{
  $("#table2 tr:first").clone().find("input").each(function() {
    $(this).val('').attr('id', function(_, id) { return id + i });
  }).end().appendTo("#table2");
  i++;
})​;​

万分感谢!您在特定表中查找特定行的语法非常有效$Table1 tr:first.clone。正是我需要的!谢谢你的帮助!从特定表中唯一标识特定行的语法如下:Table1 tr:first。非常接近!你确实让我走上了正确的道路。
$("button").click(function() ​​​{
  $("#table2 tr:first").clone().find("input").each(function() {
    $(this).val('').attr('id', function(_, id) { return id + i });
  }).end().appendTo("#table2");
  i++;
})​;​