扩展克隆表行功能

时间:2011-07-27 14:25:39

标签: jquery

这篇文章是Customizing JQuery Cloned row attributes的扩展名。

我需要做的是复制行,但要选择分配给每个元素的新名称和ID。例如,如果元素是单选按钮,我不想更改名称(用于分组目的)。

此外,在小提琴中提供的示例中,“选择”列表永远不会更新其名称或ID。

这是小提琴:http://jsfiddle.net/radi8/EwQUW/15/

作为JQuery的新手,我非常感谢任何指导和帮助让这个工作。我讨厌问愚蠢的问题,但这是我迄今为止找到的最好的董事会,并且总是收到明确,直接的答案。

1 个答案:

答案 0 :(得分:0)

试试这个

// do Add button options
$("#Add").click(function() {
    var i = ($('#secondaryEmails >tbody >tr').length)+1;
    $("#secondaryEmails >tbody tr:first").clone().find("input,select").each(function() {
        //if(this).(':radio').
        $(this).attr({
            'id': function(_, id) {
                return id + i;
            },
            'name': function(_, name) {
                if($(this).attr("type") == "radio")
                    return name;
                return name + i;
            },
            'value': ''
        });
    }).end().appendTo("#secondaryEmails >tbody").show();
});
// do update button options
$("#update").click(function() {
    // find and display selected row data
    alert('in Update');
    var rowCount = $('#secondaryEmails >tbody >tr').length;

});
// do row double click options
// do row selected by either focusing on email or ship type elements
相关问题