我想使用jQuery在每次有人按下添加行按钮时克隆表格行。请问我的代码有什么问题?我在我的视图中使用HTML + Smarty模板语言。以下是我的模板文件内容:
那我做错了什么呢?
<table>
<tr>
<td>Description</td>
<td>Unit</td>
<td>Qty</td>
<td>Total</td>
<td></td>
</tr>
<tbody id="entries">
{foreach from=$arrItem item=i name=inv}
<tr>
<td>
<input type="hidden" name="invoice_item_id[]" value="{$i.invoice_item_id}"/>
<input type="hidden" name="assignment_id[]" value="{$i.assignment_id}" />
<input type="text" name="description[]" value="{$i.description}"/>
</td>
<td><input type="text" class="unit_cost" name="unit_cost[]" value="{$i.unit_cost}"/></td>
<td><input type="text" class="qty" name="qty[]" value="{$i.qty}"/></td>
<td><input type="text" class="cost" name="cost[]" value="{$i.cost}"/></td>
<td><a href="javascript:void(0);" class="delete-invoice-item">delete</a></td>
</tr>
{/foreach}
</tbody>
<tfoot>
<tr><td colspan="5"><input type="button" id="add-row" value="add row" /></td></tr>
</tfoot>
</table>
这是我的Jquery Javascript调用,我知道当我放入一个alert()语句时它会被触发。所以问题在于我不知道Jquery如何工作。
$('#add-row').live('click', function() {$('#entries tr:nth-child(0)').clone().appendTo('#entries');});
那我做错了什么呢?