0

我找到了一个 jquery 脚本来创建一个表,并且有一个按钮可以将行添加到表的底部。然后,当单击以删除该特定行时,每行上都有链接。在 Chrome 和 Safari 中一切正常,但在 FireFox 或 IE 中却没有。这是Jquery。

    if ($("table#data tbody tr").size() == 1) {
    $('.deleteRowButton').hide();
}

$('.deleteRowButton').live('click',function() {
    var bid = $(this).attr('id');
    var nid = bid.replace(/[^\d.]/g, "");
    var pid = $("#product" + nid).val();
    $("#productschanges").append("2:" + nid + ":" + pid + ","); 
    if ($("table#data tr").size() > 1) {
    $(this).parents('tr').first().remove();

    if ($("table#data tbody tr").size() == 1) {
        $('.deleteRowButton').hide();
    } else {
        $('.deleteRowButton').show();
    }
} else {
    $('.deleteRowButton').hide();
}
});

$(".addRowButton").click(function() {
    $("table#data tbody tr:last").clone(true).find("select").each(function() {
        $(this).attr({
            'id': function(_, id) {
                return this.id.replace(/[0-9]/g, '') + i;
            },
            'name': function(_, name) {
                return this.name.replace(/[0-9]/g, '') + i;
            },
            'value': function(_, value) {
                return '';
            }
        });
        $(this).prop('disabled', false);

    }).end().find("input").each(function() {
        $(this).attr({
            'id': function(_, id) {
                return this.id.replace(/[0-9]/g, '') + i;
            },
            'name': function(_, name) {
                return this.name.replace(/[0-9]/g, '') + i;
            },
            'value': function(_, value) {
                return '';
            }
        });

    }).end().find("button").each(function() {
        $(this).attr({
            'id': function(_, id) {
                return this.id.replace(/[0-9]/g, '') + i;
            },
        });

    }).end().appendTo("table#data tbody");
    i++;

    $('.deleteRowButton').show();
});

.deleteRowButton 中的追加适用于所有浏览器,但未按预期删除该行。关于为什么这在两个浏览器中不起作用的任何帮助?

谢谢 2Pher

4

1 回答 1

0

我查看您的源 html。我看到很多 html 标签的位置不正确。在标签样式之前有关闭标签而不是任何打开标签。您应该修复此错误。具有有效的打开标签和关闭标签。

于 2013-02-23T10:04:35.607 回答