【发布时间】:2010-08-17 14:07:26
【问题描述】:
我有一个表单,其中包含一个表格,其中包含供用户填写的项目 在。我目前已经设置好,以便用户可以添加一个额外的 行以防他们需要添加更多信息。
这很好用,但我想知道是否有办法生成 每个克隆字段的唯一 ID。
My function is currently this:
function addTableRow(table) {
$(table).append($(table + ' tr:last').clone());
return true;
}
并通过传入表 id 的 onclick 调用。
表格行包含以下信息:
<tr>
<td><input type="text" id="txtBarnParts1" name="txtBarnParts
[]"></td>
<td><input type="text" id="txtBarnWidth1" name="txtBarnWidth
[]">ft</td>
<td><input type="text" id="txtBarnRemarks1"
name="txtBarnRemarks1[]"></td>
</tr>
我想要的是当我克隆 id 的行时 以 1 递增,因此下一行将具有 id:
txtBarnParts2, txtBarnWidth2, txtBarnRemarks2...等等。
有没有办法做到这一点?
谢谢!
【问题讨论】:
标签: jquery