jquery复制当前tr行

 //复制
        var vBudgetCompileObj = (function() {
            /*table新增/移除行,参数:tableId*/
            var getMaxIndex;
            var funGenerateRow = function(tableId) {
                $("a[name='CopyTr'],a[name='DelTr']").unbind("click").click(function() {
                    var index = getMaxIndex() + 1;
                    console.log("index:" + index);
                    if ($(this).attr("name") == "CopyTr") {
                        var newHidden = $('<input type="hidden" name="tbBudCode.index" value="' + index + '">');
                        var newTr = $('<tr>').addClass("tr_row");
                        newTr.html($(this).parents('tr').html());
                        $('select', newTr).next('div').remove();
                        $(this).parents('tr').after($(newTr));
                        newTr.before(newHidden);
                        /*循环 修改input控件id和name*/
                        newTr.find("input.eaBudcode").each(function () {
                            $(this).attr("id", "tbBudCode" + index );
                            $(this).attr("name", "tbBudCode" + index );
                        });
                        newTr.find("input.eaClientCode").each(function () {
                            $(this).attr("id", "tbClientCode" + index);
                            $(this).attr("name", "tbClientCode" + index);
                        });
                        newTr.find(".eaBudName").each(function () {
                            $(this).attr("id", "tbBudName" + index);
                            $(this).attr("name", "tbBudName" + index);
                        });

                        /*循环修改select控件的value、id和name*/
                        newTr.find("select.eaDept").each(function () {
                            $(this).attr("id", "ddlDept" + index);
                            $(this).attr("name", "ddlDept" + index);
                        });
                        newTr.find("select.eaBrand").each(function () {
                            $(this).attr("id", "ddlBrand" + index);
                            $(this).attr("name", "ddlBrand" + index);
                        });
                        newTr.find("select.eaBudItem").each(function () {
                            $(this).attr("id", "ddlBudItem" + index);
                            $(this).attr("name", "ddlBudItem" + index);
                        });
                        newTr.find("select.eaCompany").each(function () {
                            $(this).attr("id","ddlCompany"+ index);
                            $(this).attr("name","ddlCompany"+ index);
                        });
                        newTr.find("select.eaCurrency").each(function () {
                            $(this).attr("id", "ddlCurrency" + index);
                            $(this).attr("name", "ddlCurrency" + index);
                        });
                        $('select', newTr).chosen({ width : '100%' }); //初始化复制行下拉框   
                        funGenerateRow(tableId);
                    } else {
                        if (confirm("是否删除?")) {
                            $(this).parents('tr').remove(); //移除行                                            
                        }
                    }
                    //显示行号          
                    var thisIndex = 0;
                    $("#" + tableId + " tbody>tr.tr_row").each(function() {
                        var $td = $(this).children('td');
                        thisIndex++;
                        var thisRowIndex = $('<span class="badge badge-info">' + thisIndex + '</span>');
                        $td.eq(0).html(thisRowIndex);
                    });
                });
            }
<table class = "table jtable table-bordered table-striped" id = "table_1" >
                                            <thead>
                                            <tr>
                                                <th style = " 50px;" >序号</th>
                                                <th style = " 150px;" >预算编号</th>
                                                <th style = " 100px;" >参考编号</th>
                                                <th style = " 220px;" >预算名称</th>
                                                <th style = " 100px;" >部门</th>
                                                <th style = " 100px;" >品牌</th>
                                                <th style = " 100px;" >预算科目</th>
                                                <th style = " 50px;" >公司</th>
                                                <th style = " 100px;" >预算币种</th>
                                                <th style=" 50px;">操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr class = "tr_row" >
                                                <td>
                                                    <span class="label label-sm label-success label-mini"> 1 </span>
                                                </td>                                                                                                 
                                                <td>
                                                    <input class = "form-control input-sm txt-required valid  eaBudcode" id = "tbBudCode" name = "tbBudCode" type = "text" value = "REHA1B1" placeholder = "支持系统生成/用户输入,系统内唯一即可"/>
                                                </td>
                                                <td>                                                                                   
                                                    <input class = "form-control input-sm  eaClientCode" id = "tbClientCode" name = "tbClientCode" type = "text" value = ""/>
                                                </td>
                                                <td>                                                                             
                                                    <textarea rows = "2" class = "form-control input-sm txt-required valid   eaBudName" id = "tbBudName" name = "tbBudName" >雅培-华北-A&P-半年度预算</textarea>
                                                </td>
                                                <td>
                                                    <select class = "fk-select form-control  eaDept" id = "ddlDept" name="ddlDept" ></select> 
                                                </td>
                                                <td>
                                                    <select class = "fk-select form-control eaBrand" id = "ddlBrand" name="ddlBrand" >   
                                                    </select>
                                                </td>
                                                <td>
                                                    <select class = "fk-select form-control eaBudItem" id = "ddlBudItem" name="ddlBudItem">   
                                                    </select>
                                                </td>
                                                <td>
                                                    <select class = "fk-select form-control eaCompany" id = "ddlCompany"  name="ddlCompany">     
                                                    </select>
                                                </td>
                                                <td>
                                                    <select class = "fk-select form-control  eaCurrency" id = "ddlCurrency" name="ddlCurrency" > 
                                                    </select>
                                                </td>
                                                <td>
                                                    <div class="input-group btn-group-xs  margin-bottom-5">
                                                        <span class="input-group-btn margin-top-5" data-title="faplus">
                                                            <a href="javascript:void(0);" class="btn default btn-xs" name="CopyTr" title="复制"><i class="fa fa-plus"></i></a>
                                                        </span>
                                                        <span class="input-group-btn " data-title="faplus">
                                                            <a href="javascript:void(0);" class="btn default btn-xs" name="DelTr" title="删除"><i class="fa fa-minus"></i></a>
                                                        </span>
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>


原文地址:https://www.cnblogs.com/MartinLee/p/7622621.html