Extending Clone Table Rows functionality - changing row ID

前端 未结 2 1354
情书的邮戳
情书的邮戳 2021-01-13 23:16

I have this fiddle at: http://jsfiddle.net/radi8/EwQUW/33/

Notice that the initial table is defined is:

2条回答
  •  春和景丽
    2021-01-13 23:39

    Maybe I'm missing something but this should be as easy as setting the ID attribute:

    var $clone = $("#template").clone();
    var index = $("table.reference tr:not(.template)").length;
    $clone.attr("id", "emlRow_" + index);
    

    UPDATES

    var count = $("table.reference tr").length;

    $("#Add").click(function() {
        count++;
        var $clone = $("#secondaryEmails tbody tr:first").clone();
        $clone.attr({
            id: "emlRow_" + count,
            name: "emlRow_" + count,
            style: "" // remove "display:none"
        });
        $clone.find("input,select").each(function(){
            $(this).attr({
                id: $(this).attr("id") + count,
                name: $(this).attr("name") + count
            });
        });
        $("#secondaryEmails tbody").append($clone);
    });
    

    working example: http://jsfiddle.net/hunter/EwQUW/35/

提交回复
热议问题