jQuery   发布时间:2022-04-19  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jquery – 克隆表的第n行?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
每次有人按下添加行按钮时,我都会尝试使用 jquery来克隆表格行.谁能告诉我我的代码有什么问题?我在视图中使用HTML smarty模板语言.这是我的模板文件的样子:

<table>
            <tr>
                    <td>Description</td>
                    <td>Unit</td>
                    <td>Qty</td>
                    <td>@R_447_10586@l</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');});

那么我做错了什么?

解决方法

首先,没有nth-child(0)这样的东西,nth-child以1开头

大佬总结

以上是大佬教程为你收集整理的jquery – 克隆表的第n行?全部内容,希望文章能够帮你解决jquery – 克隆表的第n行?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。