我正在克隆表中的最后一行,但我需要为每个输入提供唯一的多维名称......
<tr>
<td><input type="text" name='input[1][Name]'></input></td>
<td><input type="text" name='input[1][address]'></input></td>
<td><input type="text" name='input[1][contactInfo]'></input></td>
</tr>
下一行应该是
<tr>
<td><input type="text" name='input[2][Name]'></input></td>
<td><input type="text" name='input[2][address]'></input></td>
<td><input type="text" name='input[2][contactInfo]'></input></td>
</tr>
...... jQuery
$(".alternativeRow").click(function(){
i=2;
$("table tr:last").clone().find("input").each(function() {
$(this).attr({
'id': function(_, id) { return id + i },
'name': function(_, name) { return name + i },
'value': ''
});
}).end().appendTo("table");
i++;
});