我有一个带有“添加”按钮的表格。当您单击此按钮时,我希望在当前行下面创建一行新的表格行。我还希望这一行中的输入字段为空。我正在尝试使用 .clone() 实现此目的,但它会克隆页面上的所有行。请帮忙解决。谢谢。
$("input.tr_clone_add")
.live('click', function(){
$(this).closest('.tr_clone')
.clone()
.insertAfter(".tr_clone")
});
HTML
=>HTML
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="table-data">
<tr>
<td>Name</td>
<td>Location</td>
<td>From</td>
<td>To</td>
<td>Add</td>
</tr>
<tr class="tr_clone">
<td><input type="text" autofocus placeholder="who" name="who" ></td>
<td><input type="text" autofocus placeholder="location" name="location" ></td>
<td><input type="text" placeholder="Start Date" name="datepicker_start" class="datepicker"></td>
<td><input type="text" placeholder="End Date" name="datepicker_end" class="datepicker"></td>
<td><input type="button" name="add" value="Add" class="tr_clone_add"></td>
</tr>
</table><!-- /table#table-data -->
name
参数以避免数据冲突(即新行中输入的值覆盖克隆行的值)...? - Tommwidth
,border
,cellpadding
和cellspacing
属性已被弃用,应改用CSS样式。请转换为CSS。(2)对于表头单元格,请使用TH而不是TD元素。(3)您不能拥有多个自动聚焦字段。 - Šime Vidas