gpt4 book ai didi

JQuery 循环克隆

转载 作者:行者123 更新时间:2023-12-01 08:18:33 24 4
gpt4 key购买 nike

尝试让我的 1 个表行自动克隆 24 次,然后使用“添加行 +”按钮来克隆其他行。

示例可以在这里找到:http://jsfiddle.net/CzZxf/17/

var uniqueIds = $("#math-table tr").length;
$("#button").click(function(){
var $thisRow = $(this).closest("tr"),
$clone = $thisRow.removeClass().clone(), // Clone row
$inputs = $clone.find("input").val("").removeClass();
uniqueIds++; //Increment ID
$inputs[0].id = "A" + uniqueIds;
$inputs[1].id = "B" + uniqueIds;
$inputs[2].id = "C" + uniqueIds;


$thisRow.after($clone);
});

最佳答案

您误解了.closest,它的工作原理与.parents类似。

我修复了遍历以在此处查找最后一个tr:http://jsfiddle.net/CzZxf/19/

var $thisRow = $("#math-table tr:last-child")

关于JQuery 循环克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8843018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com