【问题标题】:Extending Clone Table Rows functionality扩展克隆表行功能
【发布时间】:2011-07-27 14:25:39
【问题描述】:

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

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

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

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

作为 JQuery 的新手,我非常感谢任何指导和帮助以使其正常工作。我讨厌问愚蠢的问题,但这是迄今为止我找到的最好的板子,而且总是能得到清晰、直接的答案。

【问题讨论】:

    标签: jquery


    【解决方案1】:

    试试这个

    // 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
    

    【讨论】:

    • 我错过了这个:$("#secondaryEmails >tbody tr:first").clone().find("input,select").each(function() { 而这个:if( $(this).attr("type") == "radio")。一旦我明白了,其余的就会到位!!!再次感谢您的出色帮助和支持。这个项目会运行良好。
    猜你喜欢
    • 2023-02-12
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    相关资源
    最近更新 更多